sequence
stringlengths
1.25k
34.6k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'distance_diagonal_law'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'positions'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '18', '57', '71', '90', '94', '117', '181', '188']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '18', 'type': 'if_statement', 'children': ['19', '22', '48']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'positions'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'list_comprehension', 'children': ['30', '42']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'average'},{'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': 'np'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'diagonal'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'j'},{'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': 'n'},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'contigs'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'positions_to_contigs'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'positions'},{'id': '57', 'type': 'function_definition', 'children': ['58', '59', '62']},{'id': '58', 'type': 'function_name', 'children': [], 'value': 'is_intra'},{'id': '59', 'type': 'parameters', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '68'], 'value': '=='},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'contigs'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'contigs'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'max_intra_distance'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'generator_expression', 'children': ['78', '84']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '=='},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'contigs'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'contigs'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'intra_contacts'},{'id': '93', 'type': 'list', 'children': [], 'value': '[]'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'inter_contacts'},{'id': '97', 'type': 'list_comprehension', 'children': ['98', '110']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'average'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'diagonal'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '110', 'type': 'for_in_clause', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'max_intra_distance'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '117', 'type': 'for_statement', 'children': ['118', '119', '123']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'max_intra_distance'},{'id': '123', 'type': 'block', 'children': ['124', '134', '164']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'diagonal'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '134', 'type': 'for_statement', 'children': ['135', '136', '143']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '143', 'type': 'block', 'children': ['144', '148']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'diagonal_intra'},{'id': '147', 'type': 'list', 'children': [], 'value': '[]'},{'id': '148', 'type': 'if_statement', 'children': ['149', '154']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'is_intra'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '154', 'type': 'block', 'children': ['155']},{'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': 'diagonal_intra'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'intra_contacts'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'average'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'diagonal_intra'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'intra_contacts'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'inter_contacts'},{'id': '188', 'type': 'return_statement', 'children': ['189']},{'id': '189', 'type': 'list', 'children': ['190', '191'], 'value': '[positions, np.array(intra_contacts)]'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'positions'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'intra_contacts'}
def distance_diagonal_law(matrix, positions=None): n = min(matrix.shape) if positions is None: return np.array([np.average(np.diagonal(matrix, j)) for j in range(n)]) else: contigs = positions_to_contigs(positions) def is_intra(i, j): return contigs[i] == contigs[j] max_intra_distance = max((len(contigs == u) for u in set(contigs))) intra_contacts = [] inter_contacts = [np.average(np.diagonal(matrix, j)) for j in range(max_intra_distance, n)] for j in range(max_intra_distance): D = np.diagonal(matrix, j) for i in range(len(D)): diagonal_intra = [] if is_intra(i, j): diagonal_intra.append(D[i]) intra_contacts.append(np.average(np.array(diagonal_intra))) intra_contacts.extend(inter_contacts) return [positions, np.array(intra_contacts)]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'contigs_to_positions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'contigs'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'binning'},{'id': '7', 'type': 'integer', 'children': [], 'value': '10000'},{'id': '8', 'type': 'block', 'children': ['9', '18', '22', '65']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'positions'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'zeros_like'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'contigs'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'for_statement', 'children': ['23', '26', '32']},{'id': '23', 'type': 'pattern_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'groubpy'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'contigs'},{'id': '32', 'type': 'block', 'children': ['33', '40', '61']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '50']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'positions'},{'id': '44', 'type': 'slice', 'children': ['45', '46', '47']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '46', 'type': 'colon', 'children': []},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '50', 'type': 'binary_operator', 'children': ['51', '60'], 'value': '*'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'binning'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'augmented_assignment', 'children': ['63', '64'], 'value': '+='},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'positions'}
def contigs_to_positions(contigs, binning=10000): positions = np.zeros_like(contigs) index = 0 for _, chunk in itertools.groubpy(contigs): l = len(chunk) positions[index : index + l] = np.arange(list(chunk)) * binning index += l return positions
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_nearest'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13', '18', '31']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '<='},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '10', 'type': 'subscript', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '12', 'type': 'integer', 'children': [], 'value': '0'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'subscript', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'elif_clause', 'children': ['19', '25']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '>='},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '23', 'type': 'unary_operator', 'children': ['24'], 'value': '-'},{'id': '24', 'type': 'integer', 'children': [], 'value': '1'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '29', 'type': 'unary_operator', 'children': ['30'], 'value': '-'},{'id': '30', 'type': 'integer', 'children': [], 'value': '1'},{'id': '31', 'type': 'else_clause', 'children': ['32']},{'id': '32', 'type': 'block', 'children': ['33', '41', '49']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'find_le'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'find_ge'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '49', 'type': 'if_statement', 'children': ['50', '59', '62']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '55'], 'value': '>'},{'id': '51', 'type': '()', 'children': ['52']},{'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '-'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '55', 'type': '()', 'children': ['56']},{'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '-'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '62', 'type': 'else_clause', 'children': ['63']},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'lower'}
def find_nearest(sorted_list, x): if x <= sorted_list[0]: return sorted_list[0] elif x >= sorted_list[-1]: return sorted_list[-1] else: lower = find_le(sorted_list, x) upper = find_ge(sorted_list, x) if (x - lower) > (upper - x): return upper else: return lower
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'execute'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'input_params'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'cwd'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '31', '49', '53', '68', '72', '80', '100', '106', '116', '120', '146', '155', '180', '198']},{'id': '10', 'type': 'try_statement', 'children': ['11', '21']},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'taskengine_exe'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': "'engine'"},{'id': '21', 'type': 'except_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'NoConfigOptionError'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'raise_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'TaskEngineNotFoundError'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '+'},{'id': '29', 'type': 'string', 'children': [], 'value': '"Task Engine config option not set."'},{'id': '30', 'type': 'string', 'children': [], 'value': '"\\nPlease verify the \'engine\' configuration setting."'},{'id': '31', 'type': 'if_statement', 'children': ['32', '41']},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'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': 'os'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'taskengine_exe'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'raise_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'TaskEngineNotFoundError'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '+'},{'id': '47', 'type': 'string', 'children': [], 'value': '"Task Engine executable not found."'},{'id': '48', 'type': 'string', 'children': [], 'value': '"\\nPlease verify the \'engine\' configuration setting."'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'engine_args'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'try_statement', 'children': ['54', '64']},{'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': 'engine_args'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'string', 'children': [], 'value': "'engine-args'"},{'id': '64', 'type': 'except_clause', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'NoConfigOptionError'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'pass_statement', 'children': []},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '71', 'type': 'None', 'children': []},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'config_environment'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'get_environment'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'if_statement', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'config_environment'},{'id': '82', 'type': 'block', 'children': ['83', '93']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'config_environment'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '103', 'type': 'list', 'children': ['104', '105'], 'value': '[taskengine_exe, engine]'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'taskengine_exe'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '106', 'type': 'if_statement', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'engine_args'},{'id': '108', 'type': 'block', 'children': ['109']},{'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': 'args'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'engine_args'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'startupinfo'},{'id': '119', 'type': 'None', 'children': []},{'id': '120', 'type': 'if_statement', 'children': ['121', '129']},{'id': '121', 'type': 'call', 'children': ['122', '127']},{'id': '122', 'type': 'attribute', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'string', 'children': [], 'value': "'win'"},{'id': '129', 'type': 'block', 'children': ['130', '138']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'startupinfo'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'STARTUPINFO'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'augmented_assignment', 'children': ['140', '143'], 'value': '|='},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'startupinfo'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'dwFlags'},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'STARTF_USESHOWWINDOW'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'input_json'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'input_params'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162', '165', '168', '171', '174', '177']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'cwd'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'cwd'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'startupinfo'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'startupinfo'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '185']},{'id': '182', 'type': 'pattern_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'communicate'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'input_json'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '198', 'type': 'if_statement', 'children': ['199', '204', '234']},{'id': '199', 'type': 'comparison_operator', 'children': ['200', '203'], 'value': '!='},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'returncode'},{'id': '203', 'type': 'integer', 'children': [], 'value': '0'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'if_statement', 'children': ['206', '209', '220']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': '!='},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '208', 'type': 'string', 'children': [], 'value': "''"},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'raise_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'TaskEngineExecutionError'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '220', 'type': 'else_clause', 'children': ['221']},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'raise_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'TaskEngineExecutionError'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'binary_operator', 'children': ['227', '228'], 'value': '+'},{'id': '227', 'type': 'string', 'children': [], 'value': "'Task Engine exited with code: '"},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'returncode'},{'id': '234', 'type': 'else_clause', 'children': ['235']},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'return_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '241', 'type': 'argument_list', 'children': ['242', '248']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'object_pairs_hook'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}
def execute(input_params, engine, cwd=None): try: taskengine_exe = config.get('engine') except NoConfigOptionError: raise TaskEngineNotFoundError( "Task Engine config option not set." + "\nPlease verify the 'engine' configuration setting.") if not os.path.exists(taskengine_exe): raise TaskEngineNotFoundError( "Task Engine executable not found." + "\nPlease verify the 'engine' configuration setting.") engine_args = None try: engine_args = config.get('engine-args') except NoConfigOptionError: pass environment = None config_environment = config.get_environment() if config_environment: environment = os.environ.copy() environment.update(config_environment) args = [taskengine_exe, engine] if engine_args: args.append(engine_args) startupinfo = None if sys.platform.startswith('win'): startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW input_json = json.dumps(input_params) process = Popen(args, stdout=PIPE, stdin=PIPE, stderr=PIPE, cwd=cwd, env=environment, startupinfo=startupinfo) stdout, stderr = process.communicate(input=input_json.encode('utf-8')) if process.returncode != 0: if stderr != '': raise TaskEngineExecutionError(stderr.decode('utf-8')) else: raise TaskEngineExecutionError( 'Task Engine exited with code: ' + str(process.returncode)) else: return json.loads(stdout.decode('utf-8'), object_pairs_hook=OrderedDict)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_fasta'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fasta_file'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '6', 'type': 'block', 'children': ['7', '44', '95', '121', '141', '151', '157', '270', '296', '305', '317']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'chunk_lexicographic_order'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '11', 'type': 'block', 'children': ['12', '21', '30', '37']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'chunk_fields'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'chunk_name'},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'chunk_fields'},{'id': '26', 'type': 'slice', 'children': ['27', '28']},{'id': '27', 'type': 'colon', 'children': []},{'id': '28', 'type': 'unary_operator', 'children': ['29'], 'value': '-'},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'chunk_id'},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'chunk_fields'},{'id': '35', 'type': 'unary_operator', 'children': ['36'], 'value': '-'},{'id': '36', 'type': 'integer', 'children': [], 'value': '1'},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'tuple', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'chunk_name'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'chunk_id'},{'id': '44', 'type': 'function_definition', 'children': ['45', '46', '49']},{'id': '45', 'type': 'function_name', 'children': [], 'value': 'are_consecutive'},{'id': '46', 'type': 'parameters', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'chunk1'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'chunk2'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'if_statement', 'children': ['51', '56', '59']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'in'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'set', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'chunk1'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'chunk2'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'False', 'children': []},{'id': '59', 'type': 'else_clause', 'children': ['60']},{'id': '60', 'type': 'block', 'children': ['61', '68', '75']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ord1'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'chunk_lexicographic_order'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'chunk1'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ord2'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'chunk_lexicographic_order'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'chunk2'},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '85'], 'value': 'and'},{'id': '77', 'type': '()', 'children': ['78']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': '=='},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ord1'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ord2'},{'id': '84', 'type': 'integer', 'children': [], 'value': '0'},{'id': '85', 'type': '()', 'children': ['86']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': '=='},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'ord1'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'id': '90', 'type': 'binary_operator', 'children': ['91', '94'], 'value': '+'},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ord2'},{'id': '93', 'type': 'integer', 'children': [], 'value': '1'},{'id': '94', 'type': 'integer', 'children': [], 'value': '1'},{'id': '95', 'type': 'function_definition', 'children': ['96', '97', '99']},{'id': '96', 'type': 'function_name', 'children': [], 'value': 'consecutiveness'},{'id': '97', 'type': 'parameters', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'key_chunk_pair'},{'id': '99', 'type': 'block', 'children': ['100', '106', '115']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'pattern_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'key_chunk_pair'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '111']},{'id': '108', 'type': 'pattern_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'chunk_name'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'chunk_id'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'chunk_lexicographic_order'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '115', 'type': 'return_statement', 'children': ['116']},{'id': '116', 'type': 'tuple', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'chunk_name'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '-'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'chunk_id'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '124', 'type': 'dictionary_comprehension', 'children': ['125', '132']},{'id': '125', 'type': 'pair', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '132', 'type': 'for_in_clause', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'SeqIO'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'fasta_file'},{'id': '140', 'type': 'string', 'children': [], 'value': '"fasta"'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sorted_ids'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'chunk_lexicographic_order'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'new_genome'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '156', 'type': 'argument_list', 'children': []},{'id': '157', 'type': 'for_statement', 'children': ['158', '161', '171']},{'id': '158', 'type': 'pattern_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '165', 'type': 'argument_list', 'children': ['166', '170']},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sorted_ids'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'consecutiveness'},{'id': '171', 'type': 'block', 'children': ['172', '185', '192', '198', '202', '224', '245', '264']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'chunk_range'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '177', 'type': 'argument_list', 'children': ['178', '184']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'integer', 'children': [], 'value': '1'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'first_chunk'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'chunk_range'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'my_sequence'},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'first_chunk'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'my_chunk'},{'id': '201', 'type': 'None', 'children': []},{'id': '202', 'type': 'while_statement', 'children': ['203', '204']},{'id': '203', 'type': 'string', 'children': [], 'value': '"Reading chunk range"'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'try_statement', 'children': ['206', '220']},{'id': '206', 'type': 'block', 'children': ['207', '214']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'my_chunk'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'chunk_range'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'augmented_assignment', 'children': ['216', '217'], 'value': '+='},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'my_sequence'},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'my_chunk'},{'id': '220', 'type': 'except_clause', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'break_statement', 'children': []},{'id': '224', 'type': 'try_statement', 'children': ['225', '238']},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'last_chunk_id'},{'id': '229', 'type': 'subscript', 'children': ['230', '236']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'my_chunk'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '236', 'type': 'unary_operator', 'children': ['237'], 'value': '-'},{'id': '237', 'type': 'integer', 'children': [], 'value': '1'},{'id': '238', 'type': 'except_clause', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'last_chunk_id'},{'id': '244', 'type': 'string', 'children': [], 'value': '""'},{'id': '245', 'type': 'if_statement', 'children': ['246', '247', '258']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'last_chunk_id'},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'new_chunk_id'},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'string', 'children': [], 'value': '"{}_{}"'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '255', 'type': 'argument_list', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'first_chunk'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'last_chunk_id'},{'id': '258', 'type': 'else_clause', 'children': ['259']},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'new_chunk_id'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'first_chunk'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '269']},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'new_genome'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'new_chunk_id'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'my_sequence'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'base_name'},{'id': '273', 'type': 'call', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'string', 'children': [], 'value': '"."'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'subscript', 'children': ['279', '292']},{'id': '279', 'type': 'call', 'children': ['280', '290']},{'id': '280', 'type': 'attribute', 'children': ['281', '289']},{'id': '281', 'type': 'call', 'children': ['282', '287']},{'id': '282', 'type': 'attribute', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'fasta_file'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'string', 'children': [], 'value': '"."'},{'id': '292', 'type': 'slice', 'children': ['293', '294']},{'id': '293', 'type': 'colon', 'children': []},{'id': '294', 'type': 'unary_operator', 'children': ['295'], 'value': '-'},{'id': '295', 'type': 'integer', 'children': [], 'value': '1'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'string', 'children': [], 'value': '"{}_merged.fa"'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'base_name'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'assignment', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'merged_core_file'},{'id': '308', 'type': 'call', 'children': ['309', '314']},{'id': '309', 'type': 'attribute', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '314', 'type': 'argument_list', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '317', 'type': 'with_statement', 'children': ['318', '328']},{'id': '318', 'type': 'with_clause', 'children': ['319']},{'id': '319', 'type': 'with_item', 'children': ['320']},{'id': '320', 'type': 'as_pattern', 'children': ['321', '326']},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '323', 'type': 'argument_list', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'merged_core_file'},{'id': '325', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '326', 'type': 'as_pattern_target', 'children': ['327']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'output_handle'},{'id': '328', 'type': 'block', 'children': ['329']},{'id': '329', 'type': 'for_statement', 'children': ['330', '331', '338']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'my_id'},{'id': '331', 'type': 'call', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '333', 'type': 'argument_list', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'new_genome'},{'id': '335', 'type': 'keyword_argument', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'chunk_lexicographic_order'},{'id': '338', 'type': 'block', 'children': ['339', '351']},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'call', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'output_handle'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'string', 'children': [], 'value': '">{}\\n"'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'my_id'},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'output_handle'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': 'call', 'children': ['358', '361']},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'string', 'children': [], 'value': '"{}\\n"'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '361', 'type': 'argument_list', 'children': ['362']},{'id': '362', 'type': 'subscript', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'new_genome'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'my_id'}
def merge_fasta(fasta_file, output_dir): def chunk_lexicographic_order(chunk): chunk_fields = chunk.split("_") chunk_name = chunk_fields[:-1] chunk_id = chunk_fields[-1] return (chunk_name, int(chunk_id)) def are_consecutive(chunk1, chunk2): if None in {chunk1, chunk2}: return False else: ord1 = chunk_lexicographic_order(chunk1) ord2 = chunk_lexicographic_order(chunk2) return (ord1[0] == ord2[0]) and (ord1[1] == ord2[1] + 1) def consecutiveness(key_chunk_pair): key, chunk = key_chunk_pair chunk_name, chunk_id = chunk_lexicographic_order(chunk) return (chunk_name, chunk_id - key) genome = { record.id: record.seq for record in SeqIO.parse(fasta_file, "fasta") } sorted_ids = sorted(genome, key=chunk_lexicographic_order) new_genome = dict() for _, g in itertools.groupby(enumerate(sorted_ids), consecutiveness): chunk_range = map(operator.itemgetter(1), g) first_chunk = next(chunk_range) my_sequence = genome[first_chunk] my_chunk = None while "Reading chunk range": try: my_chunk = next(chunk_range) my_sequence += genome[my_chunk] except StopIteration: break try: last_chunk_id = my_chunk.split("_")[-1] except AttributeError: last_chunk_id = "" if last_chunk_id: new_chunk_id = "{}_{}".format(first_chunk, last_chunk_id) else: new_chunk_id = first_chunk new_genome[new_chunk_id] = my_sequence base_name = ".".join(os.path.basename(fasta_file).split(".")[:-1]) output_name = "{}_merged.fa".format(base_name) merged_core_file = os.path.join(output_dir, output_name) with open(merged_core_file, "w") as output_handle: for my_id in sorted(new_genome, key=chunk_lexicographic_order): output_handle.write(">{}\n".format(my_id)) output_handle.write("{}\n".format(new_genome[my_id]))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_block'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'section_key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'file_format'},{'id': '13', 'type': 'string', 'children': [], 'value': '"mwtab"'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19', '429']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': '=='},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'file_format'},{'id': '18', 'type': 'string', 'children': [], 'value': '"mwtab"'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'for_statement', 'children': ['21', '24', '31']},{'id': '21', 'type': 'pattern_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '24', 'type': 'call', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'section_key'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '44', '86']},{'id': '32', 'type': 'if_statement', 'children': ['33', '42']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '37'], 'value': 'and'},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '=='},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'section_key'},{'id': '36', 'type': 'string', 'children': [], 'value': '"METABOLOMICS WORKBENCH"'},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'not'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'tuple', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': '"VERSION"'},{'id': '41', 'type': 'string', 'children': [], 'value': '"CREATED_ON"'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'continue_statement', 'children': []},{'id': '44', 'type': 'if_statement', 'children': ['45', '50', '60', '75']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '47', 'type': 'tuple', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': '"VERSION"'},{'id': '49', 'type': 'string', 'children': [], 'value': '"CREATED_ON"'},{'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': 'cw'},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '-'},{'id': '55', 'type': 'integer', 'children': [], 'value': '20'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '60', 'type': 'elif_clause', 'children': ['61', '65']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'tuple', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': '"SUBJECT_SAMPLE_FACTORS"'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'cw'},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '-'},{'id': '70', 'type': 'integer', 'children': [], 'value': '33'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'cw'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '-'},{'id': '81', 'type': 'integer', 'children': [], 'value': '30'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '86', 'type': 'if_statement', 'children': ['87', '90', '126', '161', '183', '260', '401']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'in'},{'id': '88', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'for_statement', 'children': ['92', '93', '99']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '103', 'type': 'argument_list', 'children': ['104', '123']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'string', 'children': [], 'value': '"{}{}{}\\t{}"'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '108', 'type': 'argument_list', 'children': ['109', '118', '119', '122']},{'id': '109', 'type': 'call', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'prefixes'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'section_key'},{'id': '117', 'type': 'string', 'children': [], 'value': '""'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '*'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'cw'},{'id': '121', 'type': 'string', 'children': [], 'value': '" "'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '126', 'type': 'elif_clause', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': '=='},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '129', 'type': 'string', 'children': [], 'value': '"SUBJECT_SAMPLE_FACTORS"'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'for_statement', 'children': ['132', '133', '134']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '138', 'type': 'argument_list', 'children': ['139', '158']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': '"{}{}\\t{}"'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145', '148']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '*'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'cw'},{'id': '147', 'type': 'string', 'children': [], 'value': '" "'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'factor'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '161', 'type': 'elif_clause', 'children': ['162', '168']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': '":UNITS"'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '172', 'type': 'argument_list', 'children': ['173', '180']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'string', 'children': [], 'value': '"{}\\t{}"'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '183', 'type': 'elif_clause', 'children': ['184', '190']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'string', 'children': [], 'value': '"_RESULTS_FILE"'},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'if_statement', 'children': ['192', '197', '232']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '194', 'type': 'argument_list', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '201', 'type': 'argument_list', 'children': ['202', '229']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': '"{}{} \\t{}\\t{}:{}"'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '206', 'type': 'argument_list', 'children': ['207', '216']},{'id': '207', 'type': 'call', 'children': ['208', '213']},{'id': '208', 'type': 'attribute', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'prefixes'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'section_key'},{'id': '215', 'type': 'string', 'children': [], 'value': '""'},{'id': '216', 'type': 'list_splat', 'children': ['217']},{'id': '217', 'type': 'list_comprehension', 'children': ['218', '219', '226']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '219', 'type': 'for_in_clause', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '225', 'type': 'argument_list', 'children': []},{'id': '226', 'type': 'for_in_clause', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '229', 'type': 'keyword_argument', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '232', 'type': 'else_clause', 'children': ['233']},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '237', 'type': 'argument_list', 'children': ['238', '257']},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'string', 'children': [], 'value': '"{}{}{}\\t{}"'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '242', 'type': 'argument_list', 'children': ['243', '252', '253', '256']},{'id': '243', 'type': 'call', 'children': ['244', '249']},{'id': '244', 'type': 'attribute', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'prefixes'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '249', 'type': 'argument_list', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'section_key'},{'id': '251', 'type': 'string', 'children': [], 'value': '""'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '*'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'cw'},{'id': '255', 'type': 'string', 'children': [], 'value': '" "'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '260', 'type': 'elif_clause', 'children': ['261', '267']},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'string', 'children': [], 'value': '"_START"'},{'id': '267', 'type': 'block', 'children': ['268', '272', '287', '295', '393']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'start_key'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'end_key'},{'id': '275', 'type': 'call', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'string', 'children': [], 'value': '"{}{}"'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '279', 'type': 'argument_list', 'children': ['280', '286']},{'id': '280', 'type': 'subscript', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'start_key'},{'id': '282', 'type': 'slice', 'children': ['283', '284']},{'id': '283', 'type': 'colon', 'children': []},{'id': '284', 'type': 'unary_operator', 'children': ['285'], 'value': '-'},{'id': '285', 'type': 'integer', 'children': [], 'value': '5'},{'id': '286', 'type': 'string', 'children': [], 'value': '"END"'},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'start_key'},{'id': '292', 'type': 'keyword_argument', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '295', 'type': 'for_statement', 'children': ['296', '297', '298']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'data_key'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '298', 'type': 'block', 'children': ['299']},{'id': '299', 'type': 'if_statement', 'children': ['300', '305', '331', '361']},{'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': 'in'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'data_key'},{'id': '302', 'type': 'tuple', 'children': ['303', '304']},{'id': '303', 'type': 'string', 'children': [], 'value': '"Samples"'},{'id': '304', 'type': 'string', 'children': [], 'value': '"Factors"'},{'id': '305', 'type': 'block', 'children': ['306']},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '309', 'type': 'argument_list', 'children': ['310', '328']},{'id': '310', 'type': 'call', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'string', 'children': [], 'value': '"{}\\t{}"'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '314', 'type': 'argument_list', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'data_key'},{'id': '316', 'type': 'call', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'subscript', 'children': ['322', '327']},{'id': '322', 'type': 'subscript', 'children': ['323', '326']},{'id': '323', 'type': 'subscript', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'section_key'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'data_key'},{'id': '328', 'type': 'keyword_argument', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '331', 'type': 'elif_clause', 'children': ['332', '336']},{'id': '332', 'type': 'comparison_operator', 'children': ['333', '334'], 'value': 'in'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'data_key'},{'id': '334', 'type': 'tuple', 'children': ['335']},{'id': '335', 'type': 'string', 'children': [], 'value': '"Fields"'},{'id': '336', 'type': 'block', 'children': ['337']},{'id': '337', 'type': 'expression_statement', 'children': ['338']},{'id': '338', 'type': 'call', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '340', 'type': 'argument_list', 'children': ['341', '358']},{'id': '341', 'type': 'call', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'string', 'children': [], 'value': '"{}"'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '345', 'type': 'argument_list', 'children': ['346']},{'id': '346', 'type': 'call', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '350', 'type': 'argument_list', 'children': ['351']},{'id': '351', 'type': 'subscript', 'children': ['352', '357']},{'id': '352', 'type': 'subscript', 'children': ['353', '356']},{'id': '353', 'type': 'subscript', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'section_key'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'data_key'},{'id': '358', 'type': 'keyword_argument', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '361', 'type': 'elif_clause', 'children': ['362', '365']},{'id': '362', 'type': 'comparison_operator', 'children': ['363', '364'], 'value': '=='},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'data_key'},{'id': '364', 'type': 'string', 'children': [], 'value': '"DATA"'},{'id': '365', 'type': 'block', 'children': ['366']},{'id': '366', 'type': 'for_statement', 'children': ['367', '368', '375']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '368', 'type': 'subscript', 'children': ['369', '374']},{'id': '369', 'type': 'subscript', 'children': ['370', '373']},{'id': '370', 'type': 'subscript', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'section_key'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'data_key'},{'id': '375', 'type': 'block', 'children': ['376']},{'id': '376', 'type': 'expression_statement', 'children': ['377']},{'id': '377', 'type': 'call', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '379', 'type': 'argument_list', 'children': ['380', '390']},{'id': '380', 'type': 'call', 'children': ['381', '384']},{'id': '381', 'type': 'attribute', 'children': ['382', '383']},{'id': '382', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '384', 'type': 'argument_list', 'children': ['385']},{'id': '385', 'type': 'call', 'children': ['386', '389']},{'id': '386', 'type': 'attribute', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '389', 'type': 'argument_list', 'children': []},{'id': '390', 'type': 'keyword_argument', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'call', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '396', 'type': 'argument_list', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'end_key'},{'id': '398', 'type': 'keyword_argument', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '401', 'type': 'else_clause', 'children': ['402']},{'id': '402', 'type': 'block', 'children': ['403']},{'id': '403', 'type': 'expression_statement', 'children': ['404']},{'id': '404', 'type': 'call', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '406', 'type': 'argument_list', 'children': ['407', '426']},{'id': '407', 'type': 'call', 'children': ['408', '411']},{'id': '408', 'type': 'attribute', 'children': ['409', '410']},{'id': '409', 'type': 'string', 'children': [], 'value': '"{}{}{}\\t{}"'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '411', 'type': 'argument_list', 'children': ['412', '421', '422', '425']},{'id': '412', 'type': 'call', 'children': ['413', '418']},{'id': '413', 'type': 'attribute', 'children': ['414', '417']},{'id': '414', 'type': 'attribute', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'prefixes'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '418', 'type': 'argument_list', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'section_key'},{'id': '420', 'type': 'string', 'children': [], 'value': '""'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '422', 'type': 'binary_operator', 'children': ['423', '424'], 'value': '*'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'cw'},{'id': '424', 'type': 'string', 'children': [], 'value': '" "'},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '426', 'type': 'keyword_argument', 'children': ['427', '428']},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '429', 'type': 'elif_clause', 'children': ['430', '433']},{'id': '430', 'type': 'comparison_operator', 'children': ['431', '432'], 'value': '=='},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'file_format'},{'id': '432', 'type': 'string', 'children': [], 'value': '"json"'},{'id': '433', 'type': 'block', 'children': ['434']},{'id': '434', 'type': 'expression_statement', 'children': ['435']},{'id': '435', 'type': 'call', 'children': ['436', '437']},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '437', 'type': 'argument_list', 'children': ['438', '452']},{'id': '438', 'type': 'call', 'children': ['439', '442']},{'id': '439', 'type': 'attribute', 'children': ['440', '441']},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '442', 'type': 'argument_list', 'children': ['443', '446', '449']},{'id': '443', 'type': 'subscript', 'children': ['444', '445']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'section_key'},{'id': '446', 'type': 'keyword_argument', 'children': ['447', '448']},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '448', 'type': 'False', 'children': []},{'id': '449', 'type': 'keyword_argument', 'children': ['450', '451']},{'id': '450', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '451', 'type': 'integer', 'children': [], 'value': '4'},{'id': '452', 'type': 'keyword_argument', 'children': ['453', '454']},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '454', 'type': 'identifier', 'children': [], 'value': 'f'}
def print_block(self, section_key, f=sys.stdout, file_format="mwtab"): if file_format == "mwtab": for key, value in self[section_key].items(): if section_key == "METABOLOMICS WORKBENCH" and key not in ("VERSION", "CREATED_ON"): continue if key in ("VERSION", "CREATED_ON"): cw = 20 - len(key) elif key in ("SUBJECT_SAMPLE_FACTORS", ): cw = 33 - len(key) else: cw = 30 - len(key) if "\n" in value: for line in value.split("\n"): print("{}{}{}\t{}".format(self.prefixes.get(section_key, ""), key, cw * " ", line), file=f) elif key == "SUBJECT_SAMPLE_FACTORS": for factor in value: print("{}{}\t{}".format(key, cw * " ", "\t".join(factor.values())), file=f) elif key.endswith(":UNITS"): print("{}\t{}".format(key, value), file=f) elif key.endswith("_RESULTS_FILE"): if isinstance(value, dict): print("{}{} \t{}\t{}:{}".format(self.prefixes.get(section_key, ""), *[i for pair in value.items() for i in pair]), file=f) else: print("{}{}{}\t{}".format(self.prefixes.get(section_key, ""), key, cw * " ", value), file=f) elif key.endswith("_START"): start_key = key end_key = "{}{}".format(start_key[:-5], "END") print(start_key, file=f) for data_key in value: if data_key in ("Samples", "Factors"): print("{}\t{}".format(data_key, "\t".join(self[section_key][key][data_key])), file=f) elif data_key in ("Fields", ): print("{}".format("\t".join(self[section_key][key][data_key])), file=f) elif data_key == "DATA": for data in self[section_key][key][data_key]: print("\t".join(data.values()), file=f) print(end_key, file=f) else: print("{}{}{}\t{}".format(self.prefixes.get(section_key, ""), key, cw * " ", value), file=f) elif file_format == "json": print(json.dumps(self[section_key], sort_keys=False, indent=4), file=f)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'retry'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ExceptionToCheck'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '7', 'type': 'integer', 'children': [], 'value': '4'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '10', 'type': 'integer', 'children': [], 'value': '3'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'backoff'},{'id': '13', 'type': 'integer', 'children': [], 'value': '2'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'status_codes'},{'id': '16', 'type': 'list', 'children': [], 'value': '[]'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '35', '44', '54', '68', '173']},{'id': '21', 'type': 'if_statement', 'children': ['22', '29']},{'id': '22', 'type': 'boolean_operator', 'children': ['23', '26'], 'value': 'or'},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'backoff'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '<='},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'backoff'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'raise_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': '"backoff must be a number greater than 0"'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'floor'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '44', 'type': 'if_statement', 'children': ['45', '48']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': '"tries must be a number 0 or greater"'},{'id': '54', 'type': 'if_statement', 'children': ['55', '62']},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '59'], 'value': 'or'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': '<='},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'raise_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': '"delay must be a number greater than 0"'},{'id': '68', 'type': 'function_definition', 'children': ['69', '70', '72']},{'id': '69', 'type': 'function_name', 'children': [], 'value': 'deco_retry'},{'id': '70', 'type': 'parameters', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '72', 'type': 'block', 'children': ['73', '171']},{'id': '73', 'type': 'function_definition', 'children': ['74', '75', '80']},{'id': '74', 'type': 'function_name', 'children': [], 'value': 'f_retry'},{'id': '75', 'type': 'parameters', 'children': ['76', '78']},{'id': '76', 'type': 'list_splat_pattern', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '78', 'type': 'dictionary_splat_pattern', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '80', 'type': 'block', 'children': ['81', '89', '163']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '86']},{'id': '83', 'type': 'pattern_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'mtries'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'mdelay'},{'id': '86', 'type': 'expression_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '89', 'type': 'while_statement', 'children': ['90', '93']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '>'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'mtries'},{'id': '92', 'type': 'integer', 'children': [], 'value': '1'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'try_statement', 'children': ['95', '104']},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '99', 'type': 'argument_list', 'children': ['100', '102']},{'id': '100', 'type': 'list_splat', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '102', 'type': 'dictionary_splat', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '104', 'type': 'except_clause', 'children': ['105', '109']},{'id': '105', 'type': 'as_pattern', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'ExceptionToCheck'},{'id': '107', 'type': 'as_pattern_target', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '109', 'type': 'block', 'children': ['110', '131', '148', '155', '159']},{'id': '110', 'type': 'if_statement', 'children': ['111', '129']},{'id': '111', 'type': '()', 'children': ['112']},{'id': '112', 'type': 'boolean_operator', 'children': ['113', '124'], 'value': 'and'},{'id': '113', 'type': 'boolean_operator', 'children': ['114', '120'], 'value': 'and'},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '119'], 'value': 'is'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'DataFailureException'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'status_codes'},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '128'], 'value': 'not'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'status_codes'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'raise_statement', 'children': []},{'id': '131', 'type': 'if_statement', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '%'},{'id': '141', 'type': 'string', 'children': [], 'value': "'%s: %s, Retrying in %s seconds.'"},{'id': '142', 'type': 'tuple', 'children': ['143', '146', '147']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'mdelay'},{'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': 'time'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'mdelay'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'augmented_assignment', 'children': ['157', '158'], 'value': '-='},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'mtries'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'augmented_assignment', 'children': ['161', '162'], 'value': '*='},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'mdelay'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'backoff'},{'id': '163', 'type': 'return_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '166', 'type': 'argument_list', 'children': ['167', '169']},{'id': '167', 'type': 'list_splat', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '169', 'type': 'dictionary_splat', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '171', 'type': 'return_statement', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'f_retry'},{'id': '173', 'type': 'return_statement', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'deco_retry'}
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, status_codes=[], logger=None): if backoff is None or backoff <= 0: raise ValueError("backoff must be a number greater than 0") tries = math.floor(tries) if tries < 0: raise ValueError("tries must be a number 0 or greater") if delay is None or delay <= 0: raise ValueError("delay must be a number greater than 0") def deco_retry(f): def f_retry(*args, **kwargs): mtries, mdelay = tries, delay while mtries > 1: try: return f(*args, **kwargs) except ExceptionToCheck as err: if (type(err) is DataFailureException and len(status_codes) and err.status not in status_codes): raise if logger: logger.warning('%s: %s, Retrying in %s seconds.' % ( f.__name__, err, mdelay)) time.sleep(mdelay) mtries -= 1 mdelay *= backoff return f(*args, **kwargs) return f_retry return deco_retry
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lcopt_bw2_autosetup'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ei_username'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ei_password'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'write_config'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ecoinvent_version'},{'id': '15', 'type': 'string', 'children': [], 'value': "'3.3'"},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ecoinvent_system_model'},{'id': '18', 'type': 'string', 'children': [], 'value': '"cutoff"'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '21', 'type': 'False', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '39', '45', '79', '85', '155', '176', '222', '234', '248', '267', '307', '420', '445', '454']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ei_name'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'string', 'children': [], 'value': '"Ecoinvent{}_{}_{}"'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '30', 'type': 'argument_list', 'children': ['31', '38']},{'id': '31', 'type': 'list_splat', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ecoinvent_version'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'ecoinvent_system_model'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'check_for_config'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'if_statement', 'children': ['46', '49']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'block', 'children': ['50', '54']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_CONFIG'},{'id': '54', 'type': 'with_statement', 'children': ['55', '67']},{'id': '55', 'type': 'with_clause', 'children': ['56']},{'id': '56', 'type': 'with_item', 'children': ['57']},{'id': '57', 'type': 'as_pattern', 'children': ['58', '65']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '60', 'type': 'argument_list', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '64', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '65', 'type': 'as_pattern_target', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '67', 'type': 'block', 'children': ['68']},{'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': 'yaml'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '76']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'default_flow_style'},{'id': '78', 'type': 'False', 'children': []},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'store_option'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'project_type'},{'id': '85', 'type': 'if_statement', 'children': ['86', '89', '124']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '=='},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'store_option'},{'id': '88', 'type': 'string', 'children': [], 'value': "'single'"},{'id': '89', 'type': 'block', 'children': ['90', '96']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'single_project_name'},{'id': '96', 'type': 'if_statement', 'children': ['97', '101']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'bw2_project_exists'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '101', 'type': 'block', 'children': ['102', '111']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'set_current'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '111', 'type': 'if_statement', 'children': ['112', '121']},{'id': '112', 'type': 'boolean_operator', 'children': ['113', '118'], 'value': 'and'},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'in'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ei_name'},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '=='},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '120', 'type': 'False', 'children': []},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'return_statement', 'children': ['123']},{'id': '123', 'type': 'True', 'children': []},{'id': '124', 'type': 'else_clause', 'children': ['125']},{'id': '125', 'type': 'block', 'children': ['126', '132']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '+'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_PROJECT_STEM'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ei_name'},{'id': '132', 'type': 'if_statement', 'children': ['133', '137']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'bw2_project_exists'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'if_statement', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '148']},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'delete_project'},{'id': '148', 'type': 'argument_list', 'children': ['149', '152']},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'delete_dir'},{'id': '154', 'type': 'True', 'children': []},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'auto_ecoinvent'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '160', 'type': 'argument_list', 'children': ['161', '164', '167', '170', '173']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'eidl'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'get_ecoinvent'},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'ei_name'},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'auto_write'},{'id': '169', 'type': 'True', 'children': []},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'ecoinvent_version'},{'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'system_model'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'ecoinvent_system_model'},{'id': '176', 'type': 'if_statement', 'children': ['177', '180']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'is'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '179', 'type': 'None', 'children': []},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'if_statement', 'children': ['182', '185']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'in'},{'id': '183', 'type': 'string', 'children': [], 'value': '"ecoinvent"'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '185', 'type': 'block', 'children': ['186', '202', '218']},{'id': '186', 'type': 'if_statement', 'children': ['187', '190']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'is'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'ei_username'},{'id': '189', 'type': 'None', 'children': []},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'ei_username'},{'id': '194', 'type': 'call', 'children': ['195', '200']},{'id': '195', 'type': 'attribute', 'children': ['196', '199']},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '198', 'type': 'string', 'children': [], 'value': "'ecoinvent'"},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '202', 'type': 'if_statement', 'children': ['203', '206']},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': 'is'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'ei_password'},{'id': '205', 'type': 'None', 'children': []},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'ei_password'},{'id': '210', 'type': 'call', 'children': ['211', '216']},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '214', 'type': 'string', 'children': [], 'value': "'ecoinvent'"},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'write_config'},{'id': '221', 'type': 'False', 'children': []},{'id': '222', 'type': 'if_statement', 'children': ['223', '226']},{'id': '223', 'type': 'comparison_operator', 'children': ['224', '225'], 'value': 'is'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'ei_username'},{'id': '225', 'type': 'None', 'children': []},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'ei_username'},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'string', 'children': [], 'value': "'ecoinvent username: '"},{'id': '234', 'type': 'if_statement', 'children': ['235', '238']},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '237'], 'value': 'is'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'ei_password'},{'id': '237', 'type': 'None', 'children': []},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'ei_password'},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'getpass'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'getpass'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'string', 'children': [], 'value': "'ecoinvent password: '"},{'id': '248', 'type': 'if_statement', 'children': ['249', '252']},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '251'], 'value': 'is'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'write_config'},{'id': '251', 'type': 'None', 'children': []},{'id': '252', 'type': 'block', 'children': ['253']},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'write_config'},{'id': '256', 'type': 'comparison_operator', 'children': ['257', '261'], 'value': 'in'},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'string', 'children': [], 'value': "'store username and password on this computer? y/[n]'"},{'id': '261', 'type': 'list', 'children': ['262', '263', '264', '265', '266'], 'value': "['y', 'Y', 'yes', 'YES', 'Yes']"},{'id': '262', 'type': 'string', 'children': [], 'value': "'y'"},{'id': '263', 'type': 'string', 'children': [], 'value': "'Y'"},{'id': '264', 'type': 'string', 'children': [], 'value': "'yes'"},{'id': '265', 'type': 'string', 'children': [], 'value': "'YES'"},{'id': '266', 'type': 'string', 'children': [], 'value': "'Yes'"},{'id': '267', 'type': 'if_statement', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'write_config'},{'id': '269', 'type': 'block', 'children': ['270', '282']},{'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': 'config'},{'id': '274', 'type': 'string', 'children': [], 'value': "'ecoinvent'"},{'id': '275', 'type': 'dictionary', 'children': ['276', '279']},{'id': '276', 'type': 'pair', 'children': ['277', '278']},{'id': '277', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'ei_username'},{'id': '279', 'type': 'pair', 'children': ['280', '281']},{'id': '280', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'ei_password'},{'id': '282', 'type': 'with_statement', 'children': ['283', '295']},{'id': '283', 'type': 'with_clause', 'children': ['284']},{'id': '284', 'type': 'with_item', 'children': ['285']},{'id': '285', 'type': 'as_pattern', 'children': ['286', '293']},{'id': '286', 'type': 'call', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '288', 'type': 'argument_list', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '292', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '293', 'type': 'as_pattern_target', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '295', 'type': 'block', 'children': ['296']},{'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': 'yaml'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '301', 'type': 'argument_list', 'children': ['302', '303', '304']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '304', 'type': 'keyword_argument', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'default_flow_style'},{'id': '306', 'type': 'False', 'children': []},{'id': '307', 'type': 'if_statement', 'children': ['308', '311', '380']},{'id': '308', 'type': 'comparison_operator', 'children': ['309', '310'], 'value': '=='},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'store_option'},{'id': '310', 'type': 'string', 'children': [], 'value': "'single'"},{'id': '311', 'type': 'block', 'children': ['312']},{'id': '312', 'type': 'if_statement', 'children': ['313', '317', '327']},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'bw2_project_exists'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '317', 'type': 'block', 'children': ['318']},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'call', 'children': ['320', '325']},{'id': '320', 'type': 'attribute', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'set_current'},{'id': '325', 'type': 'argument_list', 'children': ['326']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '327', 'type': 'else_clause', 'children': ['328']},{'id': '328', 'type': 'block', 'children': ['329']},{'id': '329', 'type': 'if_statement', 'children': ['330', '335', '351']},{'id': '330', 'type': 'not_operator', 'children': ['331']},{'id': '331', 'type': 'call', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'bw2_project_exists'},{'id': '333', 'type': 'argument_list', 'children': ['334']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_BIOSPHERE_PROJECT'},{'id': '335', 'type': 'block', 'children': ['336', '345']},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'call', 'children': ['338', '343']},{'id': '338', 'type': 'attribute', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'set_current'},{'id': '343', 'type': 'argument_list', 'children': ['344']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '345', 'type': 'expression_statement', 'children': ['346']},{'id': '346', 'type': 'call', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'bw2setup'},{'id': '350', 'type': 'argument_list', 'children': []},{'id': '351', 'type': 'else_clause', 'children': ['352']},{'id': '352', 'type': 'block', 'children': ['353', '362', '368']},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'call', 'children': ['355', '360']},{'id': '355', 'type': 'attribute', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'set_current'},{'id': '360', 'type': 'argument_list', 'children': ['361']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_BIOSPHERE_PROJECT'},{'id': '362', 'type': 'expression_statement', 'children': ['363']},{'id': '363', 'type': 'call', 'children': ['364', '367']},{'id': '364', 'type': 'attribute', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'create_core_migrations'},{'id': '367', 'type': 'argument_list', 'children': []},{'id': '368', 'type': 'expression_statement', 'children': ['369']},{'id': '369', 'type': 'call', 'children': ['370', '375']},{'id': '370', 'type': 'attribute', 'children': ['371', '374']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'copy_project'},{'id': '375', 'type': 'argument_list', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '377', 'type': 'keyword_argument', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'switch'},{'id': '379', 'type': 'True', 'children': []},{'id': '380', 'type': 'else_clause', 'children': ['381']},{'id': '381', 'type': 'block', 'children': ['382', '393', '402', '408']},{'id': '382', 'type': 'if_statement', 'children': ['383', '388']},{'id': '383', 'type': 'not_operator', 'children': ['384']},{'id': '384', 'type': 'call', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'bw2_project_exists'},{'id': '386', 'type': 'argument_list', 'children': ['387']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_BIOSPHERE_PROJECT'},{'id': '388', 'type': 'block', 'children': ['389']},{'id': '389', 'type': 'expression_statement', 'children': ['390']},{'id': '390', 'type': 'call', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'lcopt_biosphere_setup'},{'id': '392', 'type': 'argument_list', 'children': []},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'call', 'children': ['395', '400']},{'id': '395', 'type': 'attribute', 'children': ['396', '399']},{'id': '396', 'type': 'attribute', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'set_current'},{'id': '400', 'type': 'argument_list', 'children': ['401']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_BIOSPHERE_PROJECT'},{'id': '402', 'type': 'expression_statement', 'children': ['403']},{'id': '403', 'type': 'call', 'children': ['404', '407']},{'id': '404', 'type': 'attribute', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'create_core_migrations'},{'id': '407', 'type': 'argument_list', 'children': []},{'id': '408', 'type': 'expression_statement', 'children': ['409']},{'id': '409', 'type': 'call', 'children': ['410', '415']},{'id': '410', 'type': 'attribute', 'children': ['411', '414']},{'id': '411', 'type': 'attribute', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'copy_project'},{'id': '415', 'type': 'argument_list', 'children': ['416', '417']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '417', 'type': 'keyword_argument', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'switch'},{'id': '419', 'type': 'True', 'children': []},{'id': '420', 'type': 'if_statement', 'children': ['421', '428', '439']},{'id': '421', 'type': 'boolean_operator', 'children': ['422', '425'], 'value': 'and'},{'id': '422', 'type': 'comparison_operator', 'children': ['423', '424'], 'value': 'is'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'ei_username'},{'id': '424', 'type': 'None', 'children': []},{'id': '425', 'type': 'comparison_operator', 'children': ['426', '427'], 'value': 'is'},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'ei_password'},{'id': '427', 'type': 'None', 'children': []},{'id': '428', 'type': 'block', 'children': ['429']},{'id': '429', 'type': 'expression_statement', 'children': ['430']},{'id': '430', 'type': 'call', 'children': ['431', '432']},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'auto_ecoinvent'},{'id': '432', 'type': 'argument_list', 'children': ['433', '436']},{'id': '433', 'type': 'keyword_argument', 'children': ['434', '435']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'ei_username'},{'id': '436', 'type': 'keyword_argument', 'children': ['437', '438']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'ei_password'},{'id': '439', 'type': 'else_clause', 'children': ['440']},{'id': '440', 'type': 'block', 'children': ['441']},{'id': '441', 'type': 'expression_statement', 'children': ['442']},{'id': '442', 'type': 'call', 'children': ['443', '444']},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'auto_ecoinvent'},{'id': '444', 'type': 'argument_list', 'children': []},{'id': '445', 'type': 'expression_statement', 'children': ['446']},{'id': '446', 'type': 'call', 'children': ['447', '448']},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'write_search_index'},{'id': '448', 'type': 'argument_list', 'children': ['449', '450', '451']},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '450', 'type': 'identifier', 'children': [], 'value': 'ei_name'},{'id': '451', 'type': 'keyword_argument', 'children': ['452', '453']},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '454', 'type': 'return_statement', 'children': ['455']},{'id': '455', 'type': 'True', 'children': []}
def lcopt_bw2_autosetup(ei_username=None, ei_password=None, write_config=None, ecoinvent_version='3.3', ecoinvent_system_model = "cutoff", overwrite=False): ei_name = "Ecoinvent{}_{}_{}".format(*ecoinvent_version.split('.'), ecoinvent_system_model) config = check_for_config() if config is None: config = DEFAULT_CONFIG with open(storage.config_file, "w") as cfg: yaml.dump(config, cfg, default_flow_style=False) store_option = storage.project_type if store_option == 'single': project_name = storage.single_project_name if bw2_project_exists(project_name): bw2.projects.set_current(project_name) if ei_name in bw2.databases and overwrite == False: return True else: project_name = DEFAULT_PROJECT_STEM + ei_name if bw2_project_exists(project_name): if overwrite: bw2.projects.delete_project(name=project_name, delete_dir=True) auto_ecoinvent = partial(eidl.get_ecoinvent,db_name=ei_name, auto_write=True, version=ecoinvent_version, system_model=ecoinvent_system_model) if config is not None: if "ecoinvent" in config: if ei_username is None: ei_username = config['ecoinvent'].get('username') if ei_password is None: ei_password = config['ecoinvent'].get('password') write_config = False if ei_username is None: ei_username = input('ecoinvent username: ') if ei_password is None: ei_password = getpass.getpass('ecoinvent password: ') if write_config is None: write_config = input('store username and password on this computer? y/[n]') in ['y', 'Y', 'yes', 'YES', 'Yes'] if write_config: config['ecoinvent'] = { 'username': ei_username, 'password': ei_password } with open(storage.config_file, "w") as cfg: yaml.dump(config, cfg, default_flow_style=False) if store_option == 'single': if bw2_project_exists(project_name): bw2.projects.set_current(project_name) else: if not bw2_project_exists(DEFAULT_BIOSPHERE_PROJECT): bw2.projects.set_current(project_name) bw2.bw2setup() else: bw2.projects.set_current(DEFAULT_BIOSPHERE_PROJECT) bw2.create_core_migrations() bw2.projects.copy_project(project_name, switch=True) else: if not bw2_project_exists(DEFAULT_BIOSPHERE_PROJECT): lcopt_biosphere_setup() bw2.projects.set_current(DEFAULT_BIOSPHERE_PROJECT) bw2.create_core_migrations() bw2.projects.copy_project(project_name, switch=True) if ei_username is not None and ei_password is not None: auto_ecoinvent(username=ei_username, password=ei_password) else: auto_ecoinvent() write_search_index(project_name, ei_name, overwrite=overwrite) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lcopt_bw2_forwast_setup'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'use_autodownload'},{'id': '6', 'type': 'True', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'forwast_path'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'FORWAST_PROJECT_NAME'},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '43', '161', '170']},{'id': '17', 'type': 'if_statement', 'children': ['18', '19', '27', '36']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'use_autodownload'},{'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': 'forwast_filepath'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'forwast_autodownload'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'FORWAST_URL'},{'id': '27', 'type': 'elif_clause', 'children': ['28', '31']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'forwast_path'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'forwast_filepath'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'forwast_path'},{'id': '36', 'type': 'else_clause', 'children': ['37']},{'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': "'Need a path if not using autodownload'"},{'id': '43', 'type': 'if_statement', 'children': ['44', '49', '88']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': '=='},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'project_type'},{'id': '48', 'type': 'string', 'children': [], 'value': "'single'"},{'id': '49', 'type': 'block', 'children': ['50', '56']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'single_project_name'},{'id': '56', 'type': 'if_statement', 'children': ['57', '61', '71']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'bw2_project_exists'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'set_current'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'id': '72', 'type': 'block', 'children': ['73', '82']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'set_current'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'bw2setup'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'else_clause', 'children': ['89']},{'id': '89', 'type': 'block', 'children': ['90', '123', '134', '143', '149']},{'id': '90', 'type': 'if_statement', 'children': ['91', '96']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'in'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'if_statement', 'children': ['98', '99', '114']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'delete_project'},{'id': '107', 'type': 'argument_list', 'children': ['108', '111']},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'delete_dir'},{'id': '113', 'type': 'True', 'children': []},{'id': '114', 'type': 'else_clause', 'children': ['115']},{'id': '115', 'type': 'block', 'children': ['116', '121']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': "'Looks like bw2 is already set up for the FORWAST database - if you want to overwrite the existing version run lcopt.utils.lcopt_bw2_forwast_setup in a python shell using overwrite = True'"},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'False', 'children': []},{'id': '123', 'type': 'if_statement', 'children': ['124', '129']},{'id': '124', 'type': 'not_operator', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'bw2_project_exists'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_BIOSPHERE_PROJECT'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'lcopt_biosphere_setup'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '141']},{'id': '136', 'type': 'attribute', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'set_current'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_BIOSPHERE_PROJECT'},{'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': 'bw2'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'create_core_migrations'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '156']},{'id': '151', 'type': 'attribute', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'copy_project'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'db_name'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'switch'},{'id': '160', 'type': 'True', 'children': []},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'bw2'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'BW2Package'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'import_file'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'forwast_filepath'},{'id': '170', 'type': 'return_statement', 'children': ['171']},{'id': '171', 'type': 'True', 'children': []}
def lcopt_bw2_forwast_setup(use_autodownload=True, forwast_path=None, db_name=FORWAST_PROJECT_NAME, overwrite=False): if use_autodownload: forwast_filepath = forwast_autodownload(FORWAST_URL) elif forwast_path is not None: forwast_filepath = forwast_path else: raise ValueError('Need a path if not using autodownload') if storage.project_type == 'single': db_name = storage.single_project_name if bw2_project_exists(db_name): bw2.projects.set_current(db_name) else: bw2.projects.set_current(db_name) bw2.bw2setup() else: if db_name in bw2.projects: if overwrite: bw2.projects.delete_project(name=db_name, delete_dir=True) else: print('Looks like bw2 is already set up for the FORWAST database - if you want to overwrite the existing version run lcopt.utils.lcopt_bw2_forwast_setup in a python shell using overwrite = True') return False if not bw2_project_exists(DEFAULT_BIOSPHERE_PROJECT): lcopt_biosphere_setup() bw2.projects.set_current(DEFAULT_BIOSPHERE_PROJECT) bw2.create_core_migrations() bw2.projects.copy_project(db_name, switch=True) bw2.BW2Package.import_file(forwast_filepath) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_validate_samples_factors'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'mwtabfile'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'validate_samples'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'validate_factors'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '26', '40', '91']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'from_subject_samples'},{'id': '15', 'type': 'set_comprehension', 'children': ['16', '19']},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '18', 'type': 'string', 'children': [], 'value': '"local_sample_id"'},{'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '21', 'type': 'subscript', 'children': ['22', '25']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'mwtabfile'},{'id': '24', 'type': 'string', 'children': [], 'value': '"SUBJECT_SAMPLE_FACTORS"'},{'id': '25', 'type': 'string', 'children': [], 'value': '"SUBJECT_SAMPLE_FACTORS"'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'from_subject_factors'},{'id': '29', 'type': 'set_comprehension', 'children': ['30', '33']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '32', 'type': 'string', 'children': [], 'value': '"factors"'},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '35', 'type': 'subscript', 'children': ['36', '39']},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'mwtabfile'},{'id': '38', 'type': 'string', 'children': [], 'value': '"SUBJECT_SAMPLE_FACTORS"'},{'id': '39', 'type': 'string', 'children': [], 'value': '"SUBJECT_SAMPLE_FACTORS"'},{'id': '40', 'type': 'if_statement', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'validate_samples'},{'id': '42', 'type': 'block', 'children': ['43', '65']},{'id': '43', 'type': 'if_statement', 'children': ['44', '47']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'in'},{'id': '45', 'type': 'string', 'children': [], 'value': '"MS_METABOLITE_DATA"'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'mwtabfile'},{'id': '47', 'type': 'block', 'children': ['48', '61']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'from_metabolite_data_samples'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'subscript', 'children': ['55', '60']},{'id': '55', 'type': 'subscript', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'mwtabfile'},{'id': '58', 'type': 'string', 'children': [], 'value': '"MS_METABOLITE_DATA"'},{'id': '59', 'type': 'string', 'children': [], 'value': '"MS_METABOLITE_DATA_START"'},{'id': '60', 'type': 'string', 'children': [], 'value': '"Samples"'},{'id': '61', 'type': 'assert_statement', 'children': ['62']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '=='},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'from_subject_samples'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'from_metabolite_data_samples'},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'in'},{'id': '67', 'type': 'string', 'children': [], 'value': '"NMR_BINNED_DATA"'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'mwtabfile'},{'id': '69', 'type': 'block', 'children': ['70', '87']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'from_nmr_binned_data_samples'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'subscript', 'children': ['77', '84']},{'id': '77', 'type': 'subscript', 'children': ['78', '83']},{'id': '78', 'type': 'subscript', 'children': ['79', '82']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'mwtabfile'},{'id': '81', 'type': 'string', 'children': [], 'value': '"NMR_BINNED_DATA"'},{'id': '82', 'type': 'string', 'children': [], 'value': '"NMR_BINNED_DATA_START"'},{'id': '83', 'type': 'string', 'children': [], 'value': '"Fields"'},{'id': '84', 'type': 'slice', 'children': ['85', '86']},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'colon', 'children': []},{'id': '87', 'type': 'assert_statement', 'children': ['88']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '=='},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'from_subject_samples'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'from_nmr_binned_data_samples'},{'id': '91', 'type': 'if_statement', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'validate_factors'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'if_statement', 'children': ['95', '98']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'in'},{'id': '96', 'type': 'string', 'children': [], 'value': '"MS_METABOLITE_DATA"'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'mwtabfile'},{'id': '98', 'type': 'block', 'children': ['99', '112']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'from_metabolite_data_factors'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'subscript', 'children': ['106', '111']},{'id': '106', 'type': 'subscript', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'mwtabfile'},{'id': '109', 'type': 'string', 'children': [], 'value': '"MS_METABOLITE_DATA"'},{'id': '110', 'type': 'string', 'children': [], 'value': '"MS_METABOLITE_DATA_START"'},{'id': '111', 'type': 'string', 'children': [], 'value': '"Factors"'},{'id': '112', 'type': 'assert_statement', 'children': ['113']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '=='},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'from_subject_factors'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'from_metabolite_data_factors'}
def _validate_samples_factors(mwtabfile, validate_samples=True, validate_factors=True): from_subject_samples = {i["local_sample_id"] for i in mwtabfile["SUBJECT_SAMPLE_FACTORS"]["SUBJECT_SAMPLE_FACTORS"]} from_subject_factors = {i["factors"] for i in mwtabfile["SUBJECT_SAMPLE_FACTORS"]["SUBJECT_SAMPLE_FACTORS"]} if validate_samples: if "MS_METABOLITE_DATA" in mwtabfile: from_metabolite_data_samples = set(mwtabfile["MS_METABOLITE_DATA"]["MS_METABOLITE_DATA_START"]["Samples"]) assert from_subject_samples == from_metabolite_data_samples if "NMR_BINNED_DATA" in mwtabfile: from_nmr_binned_data_samples = set(mwtabfile["NMR_BINNED_DATA"]["NMR_BINNED_DATA_START"]["Fields"][1:]) assert from_subject_samples == from_nmr_binned_data_samples if validate_factors: if "MS_METABOLITE_DATA" in mwtabfile: from_metabolite_data_factors = set(mwtabfile["MS_METABOLITE_DATA"]["MS_METABOLITE_DATA_START"]["Factors"]) assert from_subject_factors == from_metabolite_data_factors
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'convert'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '5', 'type': 'block', 'children': ['6', '21', '152', '183', '232', '277', '296', '347', '378', '393', '405']},{'id': '6', 'type': 'if_statement', 'children': ['7', '14']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '9', 'type': 'argument_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Schema'},{'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': 'schema'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '21', 'type': 'if_statement', 'children': ['22', '27']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'Mapping'},{'id': '27', 'type': 'block', 'children': ['28', '32', '150']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '31', 'type': 'list', 'children': [], 'value': '[]'},{'id': '32', 'type': 'for_statement', 'children': ['33', '36', '41']},{'id': '33', 'type': 'pattern_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '46', '73', '80', '86', '97', '143']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'if_statement', 'children': ['47', '54', '67']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'Marker'},{'id': '54', 'type': 'block', 'children': ['55', '61']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'pkey'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '67', 'type': 'else_clause', 'children': ['68']},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'pkey'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'pval'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'convert'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'pval'},{'id': '84', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'pkey'},{'id': '86', 'type': 'if_statement', 'children': ['87', '90']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '89', 'type': 'None', 'children': []},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '96']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'pval'},{'id': '95', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '97', 'type': 'if_statement', 'children': ['98', '109']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '102', 'type': 'tuple', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'Required'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '109', 'type': 'block', 'children': ['110', '124']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '123']},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'pval'},{'id': '114', 'type': 'call', 'children': ['115', '122']},{'id': '115', 'type': 'attribute', 'children': ['116', '121']},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '119', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '120', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'True', 'children': []},{'id': '124', 'type': 'if_statement', 'children': ['125', '132']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '129'], 'value': 'is'},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'UNDEFINED'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '138']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'pval'},{'id': '137', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '142', 'type': 'argument_list', 'children': []},{'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': 'val'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'pval'},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '152', 'type': 'if_statement', 'children': ['153', '160']},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'All'},{'id': '160', 'type': 'block', 'children': ['161', '165', '181']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '164', 'type': 'dictionary', 'children': []},{'id': '165', 'type': 'for_statement', 'children': ['166', '167', '170']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'validators'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'convert'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '181', 'type': 'return_statement', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '183', 'type': 'if_statement', 'children': ['184', '195']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '186', 'type': 'argument_list', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '188', 'type': 'tuple', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'Clamp'},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'Range'},{'id': '195', 'type': 'block', 'children': ['196', '200', '215', '230']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '199', 'type': 'dictionary', 'children': []},{'id': '200', 'type': 'if_statement', 'children': ['201', '206']},{'id': '201', 'type': 'comparison_operator', 'children': ['202', '205'], 'value': 'is'},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '205', 'type': 'None', 'children': []},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '212']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '211', 'type': 'string', 'children': [], 'value': "'valueMin'"},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '215', 'type': 'if_statement', 'children': ['216', '221']},{'id': '216', 'type': 'comparison_operator', 'children': ['217', '220'], 'value': 'is'},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '220', 'type': 'None', 'children': []},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '227']},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '226', 'type': 'string', 'children': [], 'value': "'valueMax'"},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '230', 'type': 'return_statement', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '232', 'type': 'if_statement', 'children': ['233', '240']},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'Length'},{'id': '240', 'type': 'block', 'children': ['241', '245', '260', '275']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '244', 'type': 'dictionary', 'children': []},{'id': '245', 'type': 'if_statement', 'children': ['246', '251']},{'id': '246', 'type': 'comparison_operator', 'children': ['247', '250'], 'value': 'is'},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '250', 'type': 'None', 'children': []},{'id': '251', 'type': 'block', 'children': ['252']},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '257']},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '256', 'type': 'string', 'children': [], 'value': "'lengthMin'"},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '260', 'type': 'if_statement', 'children': ['261', '266']},{'id': '261', 'type': 'comparison_operator', 'children': ['262', '265'], 'value': 'is'},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '265', 'type': 'None', 'children': []},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '272']},{'id': '269', 'type': 'subscript', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '271', 'type': 'string', 'children': [], 'value': "'lengthMax'"},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '275', 'type': 'return_statement', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '277', 'type': 'if_statement', 'children': ['278', '285']},{'id': '278', 'type': 'call', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '280', 'type': 'argument_list', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'Datetime'},{'id': '285', 'type': 'block', 'children': ['286']},{'id': '286', 'type': 'return_statement', 'children': ['287']},{'id': '287', 'type': 'dictionary', 'children': ['288', '291']},{'id': '288', 'type': 'pair', 'children': ['289', '290']},{'id': '289', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '290', 'type': 'string', 'children': [], 'value': "'datetime'"},{'id': '291', 'type': 'pair', 'children': ['292', '293']},{'id': '292', 'type': 'string', 'children': [], 'value': "'format'"},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '296', 'type': 'if_statement', 'children': ['297', '304']},{'id': '297', 'type': 'call', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '299', 'type': 'argument_list', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'In'},{'id': '304', 'type': 'block', 'children': ['305', '331']},{'id': '305', 'type': 'if_statement', 'children': ['306', '313']},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '308', 'type': 'argument_list', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'Mapping'},{'id': '313', 'type': 'block', 'children': ['314']},{'id': '314', 'type': 'return_statement', 'children': ['315']},{'id': '315', 'type': 'dictionary', 'children': ['316', '319']},{'id': '316', 'type': 'pair', 'children': ['317', '318']},{'id': '317', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '318', 'type': 'string', 'children': [], 'value': "'select'"},{'id': '319', 'type': 'pair', 'children': ['320', '321']},{'id': '320', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'call', 'children': ['325', '330']},{'id': '325', 'type': 'attribute', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '330', 'type': 'argument_list', 'children': []},{'id': '331', 'type': 'return_statement', 'children': ['332']},{'id': '332', 'type': 'dictionary', 'children': ['333', '336']},{'id': '333', 'type': 'pair', 'children': ['334', '335']},{'id': '334', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '335', 'type': 'string', 'children': [], 'value': "'select'"},{'id': '336', 'type': 'pair', 'children': ['337', '338']},{'id': '337', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '338', 'type': 'list_comprehension', 'children': ['339', '342']},{'id': '339', 'type': 'tuple', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '342', 'type': 'for_in_clause', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '347', 'type': 'if_statement', 'children': ['348', '366']},{'id': '348', 'type': 'comparison_operator', 'children': ['349', '350'], 'value': 'in'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '350', 'type': 'tuple', 'children': ['351', '354', '357', '360', '363']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'Lower'},{'id': '354', 'type': 'attribute', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'Upper'},{'id': '357', 'type': 'attribute', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'Capitalize'},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'Title'},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'Strip'},{'id': '366', 'type': 'block', 'children': ['367']},{'id': '367', 'type': 'return_statement', 'children': ['368']},{'id': '368', 'type': 'dictionary', 'children': ['369']},{'id': '369', 'type': 'pair', 'children': ['370', '377']},{'id': '370', 'type': 'call', 'children': ['371', '376']},{'id': '371', 'type': 'attribute', 'children': ['372', '375']},{'id': '372', 'type': 'attribute', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '374', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '376', 'type': 'argument_list', 'children': []},{'id': '377', 'type': 'True', 'children': []},{'id': '378', 'type': 'if_statement', 'children': ['379', '386']},{'id': '379', 'type': 'call', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '381', 'type': 'argument_list', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '383', 'type': 'attribute', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'vol'},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'Coerce'},{'id': '386', 'type': 'block', 'children': ['387']},{'id': '387', 'type': 'expression_statement', 'children': ['388']},{'id': '388', 'type': 'assignment', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '390', 'type': 'attribute', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '393', 'type': 'if_statement', 'children': ['394', '397']},{'id': '394', 'type': 'comparison_operator', 'children': ['395', '396'], 'value': 'in'},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'TYPES_MAP'},{'id': '397', 'type': 'block', 'children': ['398']},{'id': '398', 'type': 'return_statement', 'children': ['399']},{'id': '399', 'type': 'dictionary', 'children': ['400']},{'id': '400', 'type': 'pair', 'children': ['401', '402']},{'id': '401', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '402', 'type': 'subscript', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'TYPES_MAP'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '405', 'type': 'raise_statement', 'children': ['406']},{'id': '406', 'type': 'call', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '408', 'type': 'argument_list', 'children': ['409']},{'id': '409', 'type': 'call', 'children': ['410', '413']},{'id': '410', 'type': 'attribute', 'children': ['411', '412']},{'id': '411', 'type': 'string', 'children': [], 'value': "'Unable to convert schema: {}'"},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '413', 'type': 'argument_list', 'children': ['414']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'schema'}
def convert(schema): if isinstance(schema, vol.Schema): schema = schema.schema if isinstance(schema, Mapping): val = [] for key, value in schema.items(): description = None if isinstance(key, vol.Marker): pkey = key.schema description = key.description else: pkey = key pval = convert(value) pval['name'] = pkey if description is not None: pval['description'] = description if isinstance(key, (vol.Required, vol.Optional)): pval[key.__class__.__name__.lower()] = True if key.default is not vol.UNDEFINED: pval['default'] = key.default() val.append(pval) return val if isinstance(schema, vol.All): val = {} for validator in schema.validators: val.update(convert(validator)) return val if isinstance(schema, (vol.Clamp, vol.Range)): val = {} if schema.min is not None: val['valueMin'] = schema.min if schema.max is not None: val['valueMax'] = schema.max return val if isinstance(schema, vol.Length): val = {} if schema.min is not None: val['lengthMin'] = schema.min if schema.max is not None: val['lengthMax'] = schema.max return val if isinstance(schema, vol.Datetime): return { 'type': 'datetime', 'format': schema.format, } if isinstance(schema, vol.In): if isinstance(schema.container, Mapping): return { 'type': 'select', 'options': list(schema.container.items()), } return { 'type': 'select', 'options': [(item, item) for item in schema.container] } if schema in (vol.Lower, vol.Upper, vol.Capitalize, vol.Title, vol.Strip): return { schema.__name__.lower(): True, } if isinstance(schema, vol.Coerce): schema = schema.type if schema in TYPES_MAP: return {'type': TYPES_MAP[schema]} raise ValueError('Unable to convert schema: {}'.format(schema))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_jsmin'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '19']},{'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': 'theA'},{'id': '11', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'integer', 'children': [], 'value': '3'},{'id': '19', 'type': 'while_statement', 'children': ['20', '25']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '24'], 'value': '!='},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'theA'},{'id': '24', 'type': 'string', 'children': [], 'value': "'\\000'"},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '32', '57', '123']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': '=='},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'theA'},{'id': '31', 'type': 'string', 'children': [], 'value': "' '"},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'if_statement', 'children': ['34', '40', '48']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'isAlphanum'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'theB'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'integer', 'children': [], 'value': '2'},{'id': '57', 'type': 'elif_clause', 'children': ['58', '63']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '62'], 'value': '=='},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'theA'},{'id': '62', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'if_statement', 'children': ['65', '75', '83', '97']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': 'in'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'theB'},{'id': '69', 'type': 'list', 'children': ['70', '71', '72', '73', '74'], 'value': "['{', '[', '(', '+', '-']"},{'id': '70', 'type': 'string', 'children': [], 'value': "'{'"},{'id': '71', 'type': 'string', 'children': [], 'value': "'['"},{'id': '72', 'type': 'string', 'children': [], 'value': "'('"},{'id': '73', 'type': 'string', 'children': [], 'value': "'+'"},{'id': '74', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'elif_clause', 'children': ['84', '89']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '88'], 'value': '=='},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'theB'},{'id': '88', 'type': 'string', 'children': [], 'value': "' '"},{'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': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'integer', 'children': [], 'value': '3'},{'id': '97', 'type': 'else_clause', 'children': ['98']},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'if_statement', 'children': ['100', '106', '114']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'isAlphanum'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'theB'},{'id': '106', 'type': 'block', 'children': ['107']},{'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': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'else_clause', 'children': ['115']},{'id': '115', 'type': 'block', 'children': ['116']},{'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': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'integer', 'children': [], 'value': '2'},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'if_statement', 'children': ['126', '131', '156', '210']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '=='},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'theB'},{'id': '130', 'type': 'string', 'children': [], 'value': "' '"},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'if_statement', 'children': ['133', '139', '147']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'isAlphanum'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'theA'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'integer', 'children': [], 'value': '1'},{'id': '147', 'type': 'else_clause', 'children': ['148']},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'integer', 'children': [], 'value': '3'},{'id': '156', 'type': 'elif_clause', 'children': ['157', '162']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '161'], 'value': '=='},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'theB'},{'id': '161', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'if_statement', 'children': ['164', '176', '184']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '168'], 'value': 'in'},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'theA'},{'id': '168', 'type': 'list', 'children': ['169', '170', '171', '172', '173', '174', '175'], 'value': '[\'}\', \']\', \')\', \'+\', \'-\', \'"\', \'\\\'\']'},{'id': '169', 'type': 'string', 'children': [], 'value': "'}'"},{'id': '170', 'type': 'string', 'children': [], 'value': "']'"},{'id': '171', 'type': 'string', 'children': [], 'value': "')'"},{'id': '172', 'type': 'string', 'children': [], 'value': "'+'"},{'id': '173', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '174', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '175', 'type': 'string', 'children': [], 'value': "'\\''"},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'integer', 'children': [], 'value': '1'},{'id': '184', 'type': 'else_clause', 'children': ['185']},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'if_statement', 'children': ['187', '193', '201']},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'isAlphanum'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'theA'},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'integer', 'children': [], 'value': '1'},{'id': '201', 'type': 'else_clause', 'children': ['202']},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'integer', 'children': [], 'value': '3'},{'id': '210', 'type': 'else_clause', 'children': ['211']},{'id': '211', 'type': 'block', 'children': ['212']},{'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': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': '_action'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'integer', 'children': [], 'value': '1'}
def _jsmin(self): self.theA = '\n' self._action(3) while self.theA != '\000': if self.theA == ' ': if isAlphanum(self.theB): self._action(1) else: self._action(2) elif self.theA == '\n': if self.theB in ['{', '[', '(', '+', '-']: self._action(1) elif self.theB == ' ': self._action(3) else: if isAlphanum(self.theB): self._action(1) else: self._action(2) else: if self.theB == ' ': if isAlphanum(self.theA): self._action(1) else: self._action(3) elif self.theB == '\n': if self.theA in ['}', ']', ')', '+', '-', '"', '\'']: self._action(1) else: if isAlphanum(self.theA): self._action(1) else: self._action(3) else: self._action(1)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tokenizer'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '5', 'type': 'block', 'children': ['6', '18', '393']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'deque'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '18', 'type': 'while_statement', 'children': ['19', '25']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '24'], 'value': '>'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'block', 'children': ['26', '34']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'popleft'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'if_statement', 'children': ['35', '56', '80', '142', '216']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '39', 'type': 'generator_expression', 'children': ['40', '48']},{'id': '40', 'type': 'call', 'children': ['41', '42', '45']},{'id': '41', 'type': 'string', 'children': [], 'value': '"\n yield KeyValue("'},{'id': '42', 'type': 'ERROR', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'yield'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': '"HEADER"'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'string', 'children': [], 'value': '" "'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'if_statement', 'children': ['58', '61']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'in'},{'id': '59', 'type': 'string', 'children': [], 'value': '":"'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '61', 'type': 'block', 'children': ['62', '73']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '67']},{'id': '64', 'type': 'pattern_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'string', 'children': [], 'value': '":"'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'yield', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '80', 'type': 'elif_clause', 'children': ['81', '95', '113']},{'id': '81', 'type': 'attribute', 'children': ['82', '91', '94']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88', '90']},{'id': '87', 'type': 'string', 'children': [], 'value': '"\n yield KeyValue("'},{'id': '88', 'type': 'ERROR', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'HEADER'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '91', 'type': 'ERROR', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'elif'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '95', 'type': 'ERROR', 'children': ['96', '97', '100', '101', '104']},{'id': '96', 'type': 'string', 'children': [], 'value': '"\n yield KeyValue("'},{'id': '97', 'type': 'ERROR', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'yield'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '100', 'type': 'string', 'children': [], 'value': '"\n elif line.startswith("'},{'id': '101', 'type': 'ERROR', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'yield'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '104', 'type': 'call', 'children': ['105', '111']},{'id': '105', 'type': 'attribute', 'children': ['106', '107', '110']},{'id': '106', 'type': 'string', 'children': [], 'value': '"\n yield KeyValue(line.strip(), "'},{'id': '107', 'type': 'ERROR', 'children': ['108', '109']},{'id': '108', 'type': 'escape_sequence', 'children': [], 'value': '\\n'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'string', 'children': [], 'value': '"SUBJECT_SAMPLE_FACTORS"'},{'id': '113', 'type': 'block', 'children': ['114', '128']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '122']},{'id': '116', 'type': 'pattern_list', 'children': ['117', '118', '119', '120', '121']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'subject_type'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'local_sample_id'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'additional_sample_data'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'yield', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'SubjectSampleFactors'},{'id': '132', 'type': 'argument_list', 'children': ['133', '138', '139', '140', '141']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'subject_type'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'local_sample_id'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'additional_sample_data'},{'id': '142', 'type': 'elif_clause', 'children': ['143', '149']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'string', 'children': [], 'value': '"_START"'},{'id': '149', 'type': 'block', 'children': ['150', '157']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'yield', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '154', 'type': 'argument_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '156', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '157', 'type': 'while_statement', 'children': ['158', '165']},{'id': '158', 'type': 'not_operator', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'string', 'children': [], 'value': '"_END"'},{'id': '165', 'type': 'block', 'children': ['166', '174']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'popleft'},{'id': '173', 'type': 'argument_list', 'children': []},{'id': '174', 'type': 'if_statement', 'children': ['175', '181', '193']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'string', 'children': [], 'value': '"_END"'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'yield', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '186', 'type': 'argument_list', 'children': ['187', '192']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '191', 'type': 'argument_list', 'children': []},{'id': '192', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '193', 'type': 'else_clause', 'children': ['194']},{'id': '194', 'type': 'block', 'children': ['195', '204']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'yield', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '208', 'type': 'argument_list', 'children': ['209', '212']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '211', 'type': 'integer', 'children': [], 'value': '0'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '216', 'type': 'else_clause', 'children': ['217']},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'if_statement', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'if_statement', 'children': ['222', '235', '311']},{'id': '222', 'type': 'boolean_operator', 'children': ['223', '229'], 'value': 'or'},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'string', 'children': [], 'value': '"MS:MS_RESULTS_FILE"'},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'string', 'children': [], 'value': '"NM:NMR_RESULTS_FILE"'},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'try_statement', 'children': ['237', '282']},{'id': '237', 'type': 'block', 'children': ['238', '250', '265']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '244']},{'id': '240', 'type': 'pattern_list', 'children': ['241', '242', '243']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '255']},{'id': '252', 'type': 'pattern_list', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'extra_key'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'extra_value'},{'id': '255', 'type': 'call', 'children': ['256', '263']},{'id': '256', 'type': 'attribute', 'children': ['257', '262']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '261', 'type': 'argument_list', 'children': []},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'string', 'children': [], 'value': '":"'},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'yield', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'KeyValueExtra'},{'id': '269', 'type': 'argument_list', 'children': ['270', '279', '280', '281']},{'id': '270', 'type': 'subscript', 'children': ['271', '276']},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '275', 'type': 'argument_list', 'children': []},{'id': '276', 'type': 'slice', 'children': ['277', '278']},{'id': '277', 'type': 'integer', 'children': [], 'value': '3'},{'id': '278', 'type': 'colon', 'children': []},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'extra_key'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'extra_value'},{'id': '282', 'type': 'except_clause', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '284', 'type': 'block', 'children': ['285', '296']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '290']},{'id': '287', 'type': 'pattern_list', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'yield', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '300', 'type': 'argument_list', 'children': ['301', '310']},{'id': '301', 'type': 'subscript', 'children': ['302', '307']},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '306', 'type': 'argument_list', 'children': []},{'id': '307', 'type': 'slice', 'children': ['308', '309']},{'id': '308', 'type': 'integer', 'children': [], 'value': '3'},{'id': '309', 'type': 'colon', 'children': []},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '311', 'type': 'else_clause', 'children': ['312']},{'id': '312', 'type': 'block', 'children': ['313']},{'id': '313', 'type': 'try_statement', 'children': ['314', '380']},{'id': '314', 'type': 'block', 'children': ['315', '326']},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'assignment', 'children': ['317', '320']},{'id': '317', 'type': 'pattern_list', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '320', 'type': 'call', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '326', 'type': 'if_statement', 'children': ['327', '330', '367']},{'id': '327', 'type': 'comparison_operator', 'children': ['328', '329'], 'value': 'in'},{'id': '328', 'type': 'string', 'children': [], 'value': '":"'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '330', 'type': 'block', 'children': ['331']},{'id': '331', 'type': 'if_statement', 'children': ['332', '338', '350']},{'id': '332', 'type': 'call', 'children': ['333', '336']},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'string', 'children': [], 'value': '"MS_METABOLITE_DATA:UNITS"'},{'id': '338', 'type': 'block', 'children': ['339']},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'yield', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '343', 'type': 'argument_list', 'children': ['344', '349']},{'id': '344', 'type': 'call', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '348', 'type': 'argument_list', 'children': []},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '350', 'type': 'else_clause', 'children': ['351']},{'id': '351', 'type': 'block', 'children': ['352']},{'id': '352', 'type': 'expression_statement', 'children': ['353']},{'id': '353', 'type': 'yield', 'children': ['354']},{'id': '354', 'type': 'call', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '356', 'type': 'argument_list', 'children': ['357', '366']},{'id': '357', 'type': 'subscript', 'children': ['358', '363']},{'id': '358', 'type': 'call', 'children': ['359', '362']},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '362', 'type': 'argument_list', 'children': []},{'id': '363', 'type': 'slice', 'children': ['364', '365']},{'id': '364', 'type': 'integer', 'children': [], 'value': '3'},{'id': '365', 'type': 'colon', 'children': []},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '367', 'type': 'else_clause', 'children': ['368']},{'id': '368', 'type': 'block', 'children': ['369']},{'id': '369', 'type': 'expression_statement', 'children': ['370']},{'id': '370', 'type': 'yield', 'children': ['371']},{'id': '371', 'type': 'call', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '373', 'type': 'argument_list', 'children': ['374', '379']},{'id': '374', 'type': 'call', 'children': ['375', '378']},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '378', 'type': 'argument_list', 'children': []},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '380', 'type': 'except_clause', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '382', 'type': 'block', 'children': ['383', '392']},{'id': '383', 'type': 'expression_statement', 'children': ['384']},{'id': '384', 'type': 'call', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '386', 'type': 'argument_list', 'children': ['387', '388']},{'id': '387', 'type': 'string', 'children': [], 'value': '"LINE WITH ERROR:\\n\\t"'},{'id': '388', 'type': 'call', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '390', 'type': 'argument_list', 'children': ['391']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '392', 'type': 'raise_statement', 'children': []},{'id': '393', 'type': 'ERROR', 'children': ['394', '395', '396']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'KeyValue'},{'id': '395', 'type': 'string', 'children': [], 'value': '"\n yield KeyValue("'},{'id': '396', 'type': 'ERROR', 'children': [], 'value': '!'}
def tokenizer(text): stream = deque(text.split("\n")) while len(stream) > 0: line = stream.popleft() if line.startswith(" yield KeyValue(" yield KeyValue("HEADER", line) for identifier in line.split(" "): if ":" in identifier: key, value = identifier.split(":") yield KeyValue(key, value) elif line.startswith(" yield KeyValue("HEADER", line) elif line.startswith(" yield KeyValue(" yield KeyValue(" elif line.startswith(" yield KeyValue(" yield KeyValue(line.strip(), "\n") elif line.startswith("SUBJECT_SAMPLE_FACTORS"): key, subject_type, local_sample_id, factors, additional_sample_data = line.split("\t") yield SubjectSampleFactors(key.strip(), subject_type, local_sample_id, factors, additional_sample_data) elif line.endswith("_START"): yield KeyValue(line, "\n") while not line.endswith("_END"): line = stream.popleft() if line.endswith("_END"): yield KeyValue(line.strip(), "\n") else: data = line.split("\t") yield KeyValue(data[0], tuple(data)) else: if line: if line.startswith("MS:MS_RESULTS_FILE") or line.startswith("NM:NMR_RESULTS_FILE"): try: key, value, extra = line.split("\t") extra_key, extra_value = extra.strip().split(":") yield KeyValueExtra(key.strip()[3:], value, extra_key, extra_value) except ValueError: key, value = line.split("\t") yield KeyValue(key.strip()[3:], value) else: try: key, value = line.split("\t") if ":" in key: if key.startswith("MS_METABOLITE_DATA:UNITS"): yield KeyValue(key.strip(), value) else: yield KeyValue(key.strip()[3:], value) else: yield KeyValue(key.strip(), value) except ValueError: print("LINE WITH ERROR:\n\t", repr(line)) raise yield KeyValue(" yield KeyValue("!
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_proxy'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'urlparams'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '28', '35', '39', '59', '70', '114', '123', '131', '139', '143', '180', '188', '194']},{'id': '10', 'type': 'for_statement', 'children': ['11', '14', '21']},{'id': '11', 'type': 'pattern_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'v'},{'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': 'params'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'urlparams'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'urlparams'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'full_url'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '39', 'type': 'if_statement', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '41', 'type': 'block', 'children': ['42', '55']},{'id': '42', 'type': 'if_statement', 'children': ['43', '50']},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'full_url'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'augmented_assignment', 'children': ['53', '54'], 'value': '+='},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'full_url'},{'id': '54', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'augmented_assignment', 'children': ['57', '58'], 'value': '+='},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'full_url'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'urllib2'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'Request'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'full_url'},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '75']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'if_statement', 'children': ['77', '84', '100']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '83'], 'value': '=='},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'string', 'children': [], 'value': '"host"'},{'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': 'req'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'add_header'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'header'},{'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': 'urlparse'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'else_clause', 'children': ['101']},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'add_header'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'urllib2'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'urlopen'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '130', 'type': 'argument_list', 'children': []},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'got_content_length'},{'id': '142', 'type': 'False', 'children': []},{'id': '143', 'type': 'for_statement', 'children': ['144', '145', '146']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '146', 'type': 'block', 'children': ['147', '157', '170']},{'id': '147', 'type': 'if_statement', 'children': ['148', '155']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '154'], 'value': '=='},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'string', 'children': [], 'value': '"transfer-encoding"'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'continue_statement', 'children': []},{'id': '157', 'type': 'if_statement', 'children': ['158', '165']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '164'], 'value': '=='},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'string', 'children': [], 'value': '"content-length"'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'got_content_length'},{'id': '169', 'type': 'True', 'children': []},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '177']},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '187', 'type': 'argument_list', 'children': []},{'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': 'res'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'return_statement', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'result'}
def _proxy(self, url, urlparams=None): for k,v in request.params.iteritems(): urlparams[k]=v query = urlencode(urlparams) full_url = url if query: if not full_url.endswith("?"): full_url += "?" full_url += query req = urllib2.Request(url=full_url) for header in request.headers: if header.lower() == "host": req.add_header(header, urlparse.urlparse(url)[1]) else: req.add_header(header, request.headers[header]) res = urllib2.urlopen(req) i = res.info() response.status = res.code got_content_length = False for header in i: if header.lower() == "transfer-encoding": continue if header.lower() == "content-length": got_content_length = True response.headers[header] = i[header] result = res.read() res.close() return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'attempt_open_query_permutations'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'orig_file_path'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'is_header_file'},{'id': '7', 'type': 'block', 'children': ['8', '20', '48', '109', '118', '134', '140', '146', '155', '170', '184', '200', '223']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '11', 'type': 'binary_operator', 'children': ['12', '19'], 'value': '+'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'convert_to_platform_safe'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'orig_file_path'},{'id': '19', 'type': 'string', 'children': [], 'value': '"/"'},{'id': '20', 'type': 'try_statement', 'children': ['21', '44']},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '25', 'type': 'list_comprehension', 'children': ['26', '27', '35']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '35', 'type': 'if_clause', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '44', 'type': 'except_clause', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': []},{'id': '48', 'type': 'if_statement', 'children': ['49', '50', '80']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'is_header_file'},{'id': '50', 'type': 'block', 'children': ['51', '63']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '54', 'type': 'list_comprehension', 'children': ['55', '56', '59']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '59', 'type': 'if_clause', 'children': ['60']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'},{'id': '61', 'type': 'string', 'children': [], 'value': '".http-headers"'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '66', 'type': 'list_comprehension', 'children': ['67', '68', '71']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '71', 'type': 'if_clause', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_compare_file_name'},{'id': '74', 'type': 'argument_list', 'children': ['75', '78', '79']},{'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '+'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'orig_file_path'},{'id': '77', 'type': 'string', 'children': [], 'value': '".http-headers"'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '80', 'type': 'else_clause', 'children': ['81']},{'id': '81', 'type': 'block', 'children': ['82', '94']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '85', 'type': 'list_comprehension', 'children': ['86', '87', '90']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '87', 'type': 'for_in_clause', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '90', 'type': 'if_clause', 'children': ['91']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'not'},{'id': '92', 'type': 'string', 'children': [], 'value': '".http-headers"'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '97', 'type': 'list_comprehension', 'children': ['98', '99', '102']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '99', 'type': 'for_in_clause', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '102', 'type': 'if_clause', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_compare_file_name'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107', '108']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'orig_file_path'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'url_parts'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'string', 'children': [], 'value': '"/"'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'url_parts'},{'id': '121', 'type': 'call', 'children': ['122', '132']},{'id': '122', 'type': 'attribute', 'children': ['123', '131']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'url_parts'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '130'], 'value': '-'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'url_parts'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'url_parts'},{'id': '139', 'type': 'integer', 'children': [], 'value': '0'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'url_parts'},{'id': '145', 'type': 'integer', 'children': [], 'value': '1'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'string', 'children': [], 'value': '"&"'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '158', 'type': 'list_comprehension', 'children': ['159', '160', '163']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '160', 'type': 'for_in_clause', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '163', 'type': 'if_clause', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '173', 'type': 'list_comprehension', 'children': ['174', '181']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'convert_to_platform_safe'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'unquote'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '181', 'type': 'for_in_clause', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '184', 'type': 'for_statement', 'children': ['185', '186', '187']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '191', 'type': 'list_comprehension', 'children': ['192', '193', '196']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '193', 'type': 'for_in_clause', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '196', 'type': 'if_clause', 'children': ['197']},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': 'in'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '200', 'type': 'if_statement', 'children': ['201', '207']},{'id': '201', 'type': 'comparison_operator', 'children': ['202', '206'], 'value': '=='},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '206', 'type': 'integer', 'children': [], 'value': '1'},{'id': '207', 'type': 'block', 'children': ['208', '218']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '217', 'type': 'integer', 'children': [], 'value': '0'},{'id': '218', 'type': 'return_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'open_file'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '223', 'type': 'if_statement', 'children': ['224', '230']},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '229'], 'value': '>'},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '229', 'type': 'integer', 'children': [], 'value': '1'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'raise_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'DataFailureException'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236', '239']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '236', 'type': 'binary_operator', 'children': ['237', '238'], 'value': '+'},{'id': '237', 'type': 'string', 'children': [], 'value': '"Multiple mock data files matched the "'},{'id': '238', 'type': 'string', 'children': [], 'value': '"parameters provided!"'},{'id': '239', 'type': 'integer', 'children': [], 'value': '404'}
def attempt_open_query_permutations(url, orig_file_path, is_header_file): directory = dirname(convert_to_platform_safe(orig_file_path)) + "/" try: filenames = [f for f in os.listdir(directory) if isfile(join(directory, f))] except OSError: return if is_header_file: filenames = [f for f in filenames if ".http-headers" in f] filenames = [f for f in filenames if _compare_file_name(orig_file_path + ".http-headers", directory, f)] else: filenames = [f for f in filenames if ".http-headers" not in f] filenames = [f for f in filenames if _compare_file_name(orig_file_path, directory, f)] url_parts = url.split("/") url_parts = url_parts[len(url_parts) - 1].split("?") base = url_parts[0] params = url_parts[1] params = params.split("&") filenames = [f for f in filenames if f.startswith(base)] params = [convert_to_platform_safe(unquote(p)) for p in params] for param in params: filenames = [f for f in filenames if param in f] if len(filenames) == 1: path = join(directory, filenames[0]) return open_file(path) if len(filenames) > 1: raise DataFailureException(url, "Multiple mock data files matched the " + "parameters provided!", 404)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_databases'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'search_term'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'markets_only'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'databases_to_search'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'allow_internal'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '23', '67', '104', '112', '118', '137', '158', '170', '177']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dict_list'},{'id': '22', 'type': 'list', 'children': [], 'value': '[]'},{'id': '23', 'type': 'if_statement', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'allow_internal'},{'id': '25', 'type': 'block', 'children': ['26', '30', '60']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'internal_dict'},{'id': '29', 'type': 'dictionary', 'children': []},{'id': '30', 'type': 'for_statement', 'children': ['31', '34', '43']},{'id': '31', 'type': 'pattern_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '34', 'type': 'call', 'children': ['35', '42']},{'id': '35', 'type': 'attribute', 'children': ['36', '41']},{'id': '36', 'type': 'subscript', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '40', 'type': 'string', 'children': [], 'value': "'items'"},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'if_statement', 'children': ['45', '53']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '52'], 'value': '=='},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'string', 'children': [], 'value': "'lcopt_type'"},{'id': '52', 'type': 'string', 'children': [], 'value': "'intermediate'"},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'internal_dict'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'v'},{'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': 'dict_list'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'internal_dict'},{'id': '67', 'type': 'if_statement', 'children': ['68', '71', '84']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'databases_to_search'},{'id': '70', 'type': 'None', 'children': []},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'augmented_assignment', 'children': ['74', '75'], 'value': '+='},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'dict_list'},{'id': '75', 'type': 'list_comprehension', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '78', 'type': 'string', 'children': [], 'value': "'items'"},{'id': '79', 'type': 'for_in_clause', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'external_databases'},{'id': '84', 'type': 'else_clause', 'children': ['85']},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'augmented_assignment', 'children': ['88', '89'], 'value': '+='},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dict_list'},{'id': '89', 'type': 'list_comprehension', 'children': ['90', '93', '98']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '92', 'type': 'string', 'children': [], 'value': "'items'"},{'id': '93', 'type': 'for_in_clause', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'external_databases'},{'id': '98', 'type': 'if_clause', 'children': ['99']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': 'in'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '102', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'databases_to_search'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'Dictionaries'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'list_splat', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'dict_list'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'Query'},{'id': '117', 'type': 'argument_list', 'children': []},{'id': '118', 'type': 'if_statement', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'markets_only'},{'id': '120', 'type': 'block', 'children': ['121', '130']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'market_filter'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'Filter'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128', '129']},{'id': '127', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '128', 'type': 'string', 'children': [], 'value': '"has"'},{'id': '129', 'type': 'string', 'children': [], 'value': '"market for"'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'market_filter'},{'id': '137', 'type': 'if_statement', 'children': ['138', '141']},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': 'is'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '140', 'type': 'None', 'children': []},{'id': '141', 'type': 'block', 'children': ['142', '151']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'location_filter'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'Filter'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149', '150']},{'id': '148', 'type': 'string', 'children': [], 'value': '"location"'},{'id': '149', 'type': 'string', 'children': [], 'value': '"is"'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'location'},{'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': 'query'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'location_filter'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'Filter'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168', '169']},{'id': '167', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '168', 'type': 'string', 'children': [], 'value': '"ihas"'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'search_term'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '177', 'type': 'return_statement', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'result'}
def search_databases(self, search_term, location=None, markets_only=False, databases_to_search=None, allow_internal=False): dict_list = [] if allow_internal: internal_dict = {} for k, v in self.database['items'].items(): if v.get('lcopt_type') == 'intermediate': internal_dict[k] = v dict_list.append(internal_dict) if databases_to_search is None: dict_list += [x['items'] for x in self.external_databases] else: dict_list += [x['items'] for x in self.external_databases if x['name'] in databases_to_search] data = Dictionaries(*dict_list) query = Query() if markets_only: market_filter = Filter("name", "has", "market for") query.add(market_filter) if location is not None: location_filter = Filter("location", "is", location) query.add(location_filter) query.add(Filter("name", "ihas", search_term)) result = query(data) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_parameter_map'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '24', '28', '50', '173']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'names'},{'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': 'modelInstance'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '17', 'type': 'subscript', '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': 'modelInstance'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '23', 'type': 'string', 'children': [], 'value': "'items'"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'parameter_map'},{'id': '27', 'type': 'dictionary', 'children': []},{'id': '28', 'type': 'function_definition', 'children': ['29', '30', '32']},{'id': '29', 'type': 'function_name', 'children': [], 'value': 'get_names_index'},{'id': '30', 'type': 'parameters', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'my_thing'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'subscript', 'children': ['35', '49']},{'id': '35', 'type': 'list_comprehension', 'children': ['36', '37', '45']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '37', 'type': 'for_in_clause', 'children': ['38', '41']},{'id': '38', 'type': 'pattern_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '45', 'type': 'if_clause', 'children': ['46']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': '=='},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'my_thing'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'for_statement', 'children': ['51', '54', '59']},{'id': '51', 'type': 'pattern_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'this_item'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'if_statement', 'children': ['61', '66']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '65'], 'value': '=='},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'this_item'},{'id': '64', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '65', 'type': 'string', 'children': [], 'value': "'process'"},{'id': '66', 'type': 'block', 'children': ['67', '87', '105', '116', '131', '145', '166']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'production_id'},{'id': '70', 'type': 'subscript', 'children': ['71', '86']},{'id': '71', 'type': 'list_comprehension', 'children': ['72', '75', '80']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '74', 'type': 'string', 'children': [], 'value': "'input'"},{'id': '75', 'type': 'for_in_clause', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'this_item'},{'id': '79', 'type': 'string', 'children': [], 'value': "'exchanges'"},{'id': '80', 'type': 'if_clause', 'children': ['81']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': '=='},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '84', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '85', 'type': 'string', 'children': [], 'value': "'production'"},{'id': '86', 'type': 'integer', 'children': [], 'value': '0'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'input_ids'},{'id': '90', 'type': 'list_comprehension', 'children': ['91', '94', '99']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '93', 'type': 'string', 'children': [], 'value': "'input'"},{'id': '94', 'type': 'for_in_clause', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'this_item'},{'id': '98', 'type': 'string', 'children': [], 'value': "'exchanges'"},{'id': '99', 'type': 'if_clause', 'children': ['100']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': '=='},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '103', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '104', 'type': 'string', 'children': [], 'value': "'technosphere'"},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'production_index'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'get_names_index'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'subscript', 'children': ['112', '115']},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'production_id'},{'id': '115', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'input_indexes'},{'id': '119', 'type': 'list_comprehension', 'children': ['120', '128']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'get_names_index'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'subscript', 'children': ['124', '127']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '127', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'input_ids'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'parameter_ids'},{'id': '134', 'type': 'list_comprehension', 'children': ['135', '142']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'string', 'children': [], 'value': "'n_p_{}_{}'"},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'production_index'},{'id': '142', 'type': 'for_in_clause', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'input_indexes'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'parameter_map_items'},{'id': '148', 'type': 'dictionary_comprehension', 'children': ['149', '158']},{'id': '149', 'type': 'pair', 'children': ['150', '155']},{'id': '150', 'type': 'tuple', 'children': ['151', '154']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'input_ids'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'parameter_ids'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '158', 'type': 'for_in_clause', 'children': ['159', '162']},{'id': '159', 'type': 'pattern_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'input_ids'},{'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': 'parameter_map'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'parameter_map_items'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'parameter_map'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'parameter_map'}
def create_parameter_map(self): names = self.modelInstance.names db = self.modelInstance.database['items'] parameter_map = {} def get_names_index(my_thing): return[i for i, x in enumerate(names) if x == my_thing][0] for k, this_item in db.items(): if this_item['type'] == 'process': production_id = [x['input'] for x in this_item['exchanges'] if x['type'] == 'production'][0] input_ids = [x['input'] for x in this_item['exchanges'] if x['type'] == 'technosphere'] production_index = get_names_index(db[production_id]['name']) input_indexes = [get_names_index(db[x]['name']) for x in input_ids] parameter_ids = ['n_p_{}_{}'.format(x, production_index) for x in input_indexes] parameter_map_items = {(input_ids[n], k): parameter_ids[n] for n, x in enumerate(input_ids)} parameter_map.update(parameter_map_items) self.parameter_map = parameter_map
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'apply'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'config_override'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'tag_override'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'rollback'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'skip_missing'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '24', '30', '41', '252']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_config'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'config_override'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '29', 'type': 'string', 'children': [], 'value': "'databases'"},{'id': '30', 'type': 'if_statement', 'children': ['31', '35']},{'id': '31', 'type': 'boolean_operator', 'children': ['32', '33'], 'value': 'and'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'rollback'},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'tag_override'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'raise_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': "'To rollback a migration you need to specify the database tag with `--tag`'"},{'id': '41', 'type': 'for_statement', 'children': ['42', '43', '47']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '47', 'type': 'block', 'children': ['48', '56', '68', '80', '92', '100', '108', '116', '127', '139', '151', '174', '192', '202', '242']},{'id': '48', 'type': 'if_statement', 'children': ['49', '54']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '51'], 'value': 'and'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'tag_override'},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '!='},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tag_override'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'continue_statement', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '59', 'type': 'call', 'children': ['60', '65']},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': "'engine'"},{'id': '67', 'type': 'string', 'children': [], 'value': "'mysql'"},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'host'"},{'id': '79', 'type': 'string', 'children': [], 'value': "'localhost'"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '83', 'type': 'call', 'children': ['84', '89']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': "'port'"},{'id': '91', 'type': 'integer', 'children': [], 'value': '3306'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '95', 'type': 'subscript', 'children': ['96', '99']},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '99', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '103', 'type': 'subscript', 'children': ['104', '107']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '107', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '111', 'type': 'subscript', 'children': ['112', '115']},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '115', 'type': 'string', 'children': [], 'value': "'db'"},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'add_slash'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'subscript', 'children': ['123', '126']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '126', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'pre_migration'},{'id': '130', 'type': 'call', 'children': ['131', '136']},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'string', 'children': [], 'value': "'pre_migration'"},{'id': '138', 'type': 'None', 'children': []},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'post_migration'},{'id': '142', 'type': 'call', 'children': ['143', '148']},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150']},{'id': '149', 'type': 'string', 'children': [], 'value': "'post_migration'"},{'id': '150', 'type': 'None', 'children': []},{'id': '151', 'type': 'if_statement', 'children': ['152', '153', '166']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'skip_missing'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'try_statement', 'children': ['155', '162']},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'check_exists'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '161', 'type': 'string', 'children': [], 'value': "'dir'"},{'id': '162', 'type': 'except_clause', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'continue_statement', 'children': []},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'check_exists'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '173', 'type': 'string', 'children': [], 'value': "'dir'"},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'get_connection'},{'id': '179', 'type': 'argument_list', 'children': ['180', '181', '182', '183', '184', '185', '186']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'get_ssl'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '192', 'type': 'if_statement', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'pre_migration'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'run_migration'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200', '201']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'pre_migration'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '202', 'type': 'if_statement', 'children': ['203', '204', '223']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'rollback'},{'id': '204', 'type': 'block', 'children': ['205', '215']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '%'},{'id': '210', 'type': 'string', 'children': [], 'value': "' * Rolling back %s (`%s` on %s)'"},{'id': '211', 'type': 'tuple', 'children': ['212', '213', '214']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'rollback_migration'},{'id': '218', 'type': 'argument_list', 'children': ['219', '220', '221', '222']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'rollback'},{'id': '223', 'type': 'else_clause', 'children': ['224']},{'id': '224', 'type': 'block', 'children': ['225', '235']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'binary_operator', 'children': ['230', '231'], 'value': '%'},{'id': '230', 'type': 'string', 'children': [], 'value': "' * Applying migrations for %s (`%s` on %s)'"},{'id': '231', 'type': 'tuple', 'children': ['232', '233', '234']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'apply_migrations'},{'id': '238', 'type': 'argument_list', 'children': ['239', '240', '241']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '242', 'type': 'if_statement', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'post_migration'},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'run_migration'},{'id': '248', 'type': 'argument_list', 'children': ['249', '250', '251']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'post_migration'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'engine'},{'id': '252', 'type': 'return_statement', 'children': ['253']},{'id': '253', 'type': 'True', 'children': []}
def apply(config_override=None, tag_override=None, rollback=None, skip_missing=None): config = get_config(config_override) databases = config['databases'] if rollback and not tag_override: raise RuntimeError( 'To rollback a migration you need to specify the database tag with `--tag`') for tag in sorted(databases): if tag_override and tag_override != tag: continue engine = databases[tag].get('engine', 'mysql') host = databases[tag].get('host', 'localhost') port = databases[tag].get('port', 3306) user = databases[tag]['user'] password = databases[tag]['password'] db = databases[tag]['db'] path = add_slash(databases[tag]['path']) pre_migration = databases[tag].get('pre_migration', None) post_migration = databases[tag].get('post_migration', None) if skip_missing: try: check_exists(path, 'dir') except RuntimeError: continue else: check_exists(path, 'dir') connection = get_connection( engine, host, user, port, password, db, get_ssl(databases[tag])) if pre_migration: run_migration(connection, pre_migration, engine) if rollback: print(' * Rolling back %s (`%s` on %s)' % (tag, db, engine)) rollback_migration(engine, connection, path, rollback) else: print(' * Applying migrations for %s (`%s` on %s)' % (tag, db, engine)) apply_migrations(engine, connection, path) if post_migration: run_migration(connection, post_migration, engine) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_configure_common'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'fallback_level'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'fallback_format'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'handler_name'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'handler'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'custom_args'},{'id': '12', 'type': 'string', 'children': [], 'value': "''"},{'id': '13', 'type': 'block', 'children': ['14', '30', '46', '57', '68', '77', '84', '91', '100', '125', '141']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'log_level'},{'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': 'config'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'get_option'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25', '28', '29']},{'id': '24', 'type': 'string', 'children': [], 'value': "'LOGGING'"},{'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '+'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '27', 'type': 'string', 'children': [], 'value': "'log_level'"},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'fallback_level'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'log_format_name'},{'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': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_option'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41', '44', '45']},{'id': '40', 'type': 'string', 'children': [], 'value': "'LOGGING'"},{'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '+'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '43', 'type': 'string', 'children': [], 'value': "'log_format'"},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'log_format'},{'id': '49', 'type': 'conditional_expression', 'children': ['50', '55', '56'], 'value': 'if'},{'id': '50', 'type': 'attribute', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ReportingFormats'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'log_format_name'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'log_format_name'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'fallback_format'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'log_format'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'log_format'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'custom_args'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'custom_args'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'formatter'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'Formatter'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'log_format'},{'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': 'handler'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'setFormatter'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'formatter'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'handler'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'setLevel'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'log_level'},{'id': '91', 'type': 'expression_statement', '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': 'logger'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'addHandler'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'handler'},{'id': '100', 'type': 'if_statement', 'children': ['101', '115']},{'id': '101', 'type': 'not_operator', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'isEnabledFor'},{'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': 'logging'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'getLevelName'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'log_level'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '123']},{'id': '118', 'type': 'attribute', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'setLevel'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'log_level'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '132']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'log_info'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '137'], 'value': '+'},{'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '+'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'handler_name'},{'id': '136', 'type': 'string', 'children': [], 'value': "' @ '"},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'log_level'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '148']},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'log_handlers'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'handler'}
def _configure_common( self, prefix, fallback_level, fallback_format, handler_name, handler, custom_args='' ): log_level = self.config.get_option( 'LOGGING', prefix + 'log_level', None, fallback_level ) log_format_name = self.config.get_option( 'LOGGING', prefix + 'log_format', None, None ) log_format = ReportingFormats[log_format_name].value if log_format_name else fallback_format log_format = log_format.format(custom_args=custom_args) formatter = logging.Formatter(log_format) handler.setFormatter(formatter) handler.setLevel(log_level) self.logger.addHandler(handler) if not self.logger.isEnabledFor(logging.getLevelName(log_level)): self.logger.setLevel(log_level) self.log_info.append(handler_name + ' @ ' + str(log_level)) self.log_handlers.append(handler)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_file'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'save_to'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'add_to_cache'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'force_refresh'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_lock_exclusive'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '26', '30', '69', '77', '85']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '22']},{'id': '19', 'type': 'pattern_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'uname'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'split_name'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'if_statement', 'children': ['31', '34', '63']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '34', 'type': 'block', 'children': ['35', '46']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '38', 'type': 'call', 'children': ['39', '44']},{'id': '39', 'type': 'attribute', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'lock_manager'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'lock_for'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'uname'},{'id': '46', 'type': 'if_statement', 'children': ['47', '48', '55']},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_lock_exclusive'},{'id': '48', 'type': 'block', 'children': ['49']},{'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': 'lock'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'lock_exclusive'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'else_clause', 'children': ['56']},{'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': 'lock'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'lock_shared'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'else_clause', 'children': ['64']},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'add_to_cache'},{'id': '68', 'type': 'False', 'children': []},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '76', 'type': 'argument_list', 'children': []},{'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': 'logger'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "' downloading %s'"},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '85', 'type': 'try_statement', 'children': ['86', '213']},{'id': '86', 'type': 'block', 'children': ['87', '149', '206']},{'id': '87', 'type': 'if_statement', 'children': ['88', '100']},{'id': '88', 'type': 'boolean_operator', 'children': ['89', '93'], 'value': 'or'},{'id': '89', 'type': 'not_operator', 'children': ['90']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '93', 'type': '()', 'children': ['94']},{'id': '94', 'type': 'boolean_operator', 'children': ['95', '98'], 'value': 'and'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'is'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'not_operator', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'force_refresh'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'try_statement', 'children': ['102', '127']},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'if_statement', 'children': ['104', '116']},{'id': '104', 'type': 'boolean_operator', 'children': ['105', '108'], 'value': 'and'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '108', 'type': 'call', 'children': ['109', '114']},{'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': 'local_store'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'get_file'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'save_to'},{'id': '127', 'type': 'except_clause', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'if_statement', 'children': ['131', '134', '146']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142', '143']},{'id': '141', 'type': 'string', 'children': [], 'value': '"Error getting \'%s\' from local store"'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '145', 'type': 'True', 'children': []},{'id': '146', 'type': 'else_clause', 'children': ['147']},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'raise_statement', 'children': []},{'id': '149', 'type': 'if_statement', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '153', 'type': 'block', 'children': ['154', '181', '193', '204']},{'id': '154', 'type': 'if_statement', 'children': ['155', '159']},{'id': '155', 'type': 'boolean_operator', 'children': ['156', '158'], 'value': 'and'},{'id': '156', 'type': 'not_operator', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_lock_exclusive'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'add_to_cache'},{'id': '159', 'type': 'block', 'children': ['160', '169']},{'id': '160', 'type': 'if_statement', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'unlock'},{'id': '168', 'type': 'argument_list', 'children': []},{'id': '169', 'type': 'return_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'get_file'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176', '177', '178']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'save_to'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'add_to_cache'},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': '_lock_exclusive'},{'id': '180', 'type': 'True', 'children': []},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '184', 'type': 'call', 'children': ['185', '190']},{'id': '185', 'type': 'attribute', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'get_file'},{'id': '190', 'type': 'argument_list', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'save_to'},{'id': '193', 'type': 'if_statement', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'add_to_cache'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': '_add_to_cache'},{'id': '201', 'type': 'argument_list', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'save_to'},{'id': '204', 'type': 'return_statement', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '206', 'type': 'raise_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'FiletrackerError'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '%'},{'id': '211', 'type': 'string', 'children': [], 'value': '"File not available: %s"'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '213', 'type': 'finally_clause', 'children': ['214']},{'id': '214', 'type': 'block', 'children': ['215', '224']},{'id': '215', 'type': 'if_statement', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '223', 'type': 'argument_list', 'children': []},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231', '232']},{'id': '230', 'type': 'string', 'children': [], 'value': "' processed %s in %.2fs'"},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '232', 'type': 'binary_operator', 'children': ['233', '238'], 'value': '-'},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'identifier', 'children': [], 'value': 't'}
def get_file(self, name, save_to, add_to_cache=True, force_refresh=False, _lock_exclusive=False): uname, version = split_name(name) lock = None if self.local_store: lock = self.lock_manager.lock_for(uname) if _lock_exclusive: lock.lock_exclusive() else: lock.lock_shared() else: add_to_cache = False t = time.time() logger.debug(' downloading %s', name) try: if not self.remote_store or (version is not None and not force_refresh): try: if self.local_store and self.local_store.exists(name): return self.local_store.get_file(name, save_to) except Exception: if self.remote_store: logger.warning("Error getting '%s' from local store", name, exc_info=True) else: raise if self.remote_store: if not _lock_exclusive and add_to_cache: if lock: lock.unlock() return self.get_file(name, save_to, add_to_cache, _lock_exclusive=True) vname = self.remote_store.get_file(name, save_to) if add_to_cache: self._add_to_cache(vname, save_to) return vname raise FiletrackerError("File not available: %s" % name) finally: if lock: lock.close() logger.debug(' processed %s in %.2fs', name, time.time() - t)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_stream'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'force_refresh'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'serve_from_cache'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '22', '26', '48']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '18']},{'id': '15', 'type': 'pattern_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'uname'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'split_name'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'if_statement', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '30', 'type': 'block', 'children': ['31', '42']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '34', 'type': 'call', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'lock_manager'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'lock_for'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'uname'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'lock_shared'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'try_statement', 'children': ['49', '213']},{'id': '49', 'type': 'block', 'children': ['50', '111', '206']},{'id': '50', 'type': 'if_statement', 'children': ['51', '63']},{'id': '51', 'type': 'boolean_operator', 'children': ['52', '56'], 'value': 'or'},{'id': '52', 'type': 'not_operator', 'children': ['53']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '56', 'type': '()', 'children': ['57']},{'id': '57', 'type': 'boolean_operator', 'children': ['58', '61'], 'value': 'and'},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'not_operator', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'force_refresh'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'try_statement', 'children': ['65', '89']},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'if_statement', 'children': ['67', '79']},{'id': '67', 'type': 'boolean_operator', 'children': ['68', '71'], 'value': 'and'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'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': 'local_store'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'return_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '87']},{'id': '82', 'type': 'attribute', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'get_stream'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '89', 'type': 'except_clause', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'if_statement', 'children': ['93', '96', '108']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104', '105']},{'id': '103', 'type': 'string', 'children': [], 'value': '"Error getting \'%s\' from local store"'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '107', 'type': 'True', 'children': []},{'id': '108', 'type': 'else_clause', 'children': ['109']},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'raise_statement', 'children': []},{'id': '111', 'type': 'if_statement', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '115', 'type': 'block', 'children': ['116', '197']},{'id': '116', 'type': 'if_statement', 'children': ['117', '122']},{'id': '117', 'type': 'boolean_operator', 'children': ['118', '121'], 'value': 'and'},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'serve_from_cache'},{'id': '122', 'type': 'block', 'children': ['123', '150', '188']},{'id': '123', 'type': 'if_statement', 'children': ['124', '127']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'is'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'block', 'children': ['128', '139']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '131', 'type': 'call', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'file_version'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '139', 'type': 'if_statement', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'versioned_name'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'uname'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '150', 'type': 'if_statement', 'children': ['151', '162']},{'id': '151', 'type': 'boolean_operator', 'children': ['152', '153'], 'value': 'or'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'force_refresh'},{'id': '153', 'type': 'not_operator', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '160']},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '162', 'type': 'block', 'children': ['163', '176']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '168']},{'id': '165', 'type': 'tuple_pattern', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '168', 'type': 'call', 'children': ['169', '174']},{'id': '169', 'type': 'attribute', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'get_stream'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '179', 'type': 'call', 'children': ['180', '185']},{'id': '180', 'type': 'attribute', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'add_stream'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '188', 'type': 'return_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '195']},{'id': '190', 'type': 'attribute', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'get_stream'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '197', 'type': 'return_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '204']},{'id': '199', 'type': 'attribute', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'get_stream'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '206', 'type': 'raise_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'FiletrackerError'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '%'},{'id': '211', 'type': 'string', 'children': [], 'value': '"File not available: %s"'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '213', 'type': 'finally_clause', 'children': ['214']},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'if_statement', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '223', 'type': 'argument_list', 'children': []}
def get_stream(self, name, force_refresh=False, serve_from_cache=False): uname, version = split_name(name) lock = None if self.local_store: lock = self.lock_manager.lock_for(uname) lock.lock_shared() try: if not self.remote_store or (version is not None and not force_refresh): try: if self.local_store and self.local_store.exists(name): return self.local_store.get_stream(name) except Exception: if self.remote_store: logger.warning("Error getting '%s' from local store", name, exc_info=True) else: raise if self.remote_store: if self.local_store and serve_from_cache: if version is None: version = self.remote_store.file_version(name) if version: name = versioned_name(uname, version) if force_refresh or not self.local_store.exists(name): (stream, vname) = self.remote_store.get_stream(name) name = self.local_store.add_stream(vname, stream) return self.local_store.get_stream(name) return self.remote_store.get_stream(name) raise FiletrackerError("File not available: %s" % name) finally: if lock: lock.close()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'put_file'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'to_local_store'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'to_remote_store'},{'id': '12', 'type': 'True', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'compress_hint'},{'id': '15', 'type': 'True', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '31', '36', '40', '62', '128']},{'id': '17', 'type': 'if_statement', 'children': ['18', '23']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '21'], 'value': 'and'},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'to_local_store'},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'to_remote_store'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'raise_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'concatenated_string', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': '"Neither to_local_store nor to_remote_store set "'},{'id': '30', 'type': 'string', 'children': [], 'value': '"in a call to filetracker.Client.put_file"'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'check_name'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'if_statement', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'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': 'lock'},{'id': '48', 'type': 'call', 'children': ['49', '54']},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'lock_manager'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'lock_for'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'lock'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'lock_exclusive'},{'id': '61', 'type': 'argument_list', 'children': []},{'id': '62', 'type': 'try_statement', 'children': ['63', '117']},{'id': '63', 'type': 'block', 'children': ['64', '89']},{'id': '64', 'type': 'if_statement', 'children': ['65', '76']},{'id': '65', 'type': 'boolean_operator', 'children': ['66', '73'], 'value': 'and'},{'id': '66', 'type': '()', 'children': ['67']},{'id': '67', 'type': 'boolean_operator', 'children': ['68', '69'], 'value': 'or'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'to_local_store'},{'id': '69', 'type': 'not_operator', 'children': ['70']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'versioned_name'},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'add_file'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '89', 'type': 'if_statement', 'children': ['90', '101']},{'id': '90', 'type': 'boolean_operator', 'children': ['91', '98'], 'value': 'and'},{'id': '91', 'type': '()', 'children': ['92']},{'id': '92', 'type': 'boolean_operator', 'children': ['93', '94'], 'value': 'or'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'to_remote_store'},{'id': '94', 'type': 'not_operator', 'children': ['95']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'local_store'},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'versioned_name'},{'id': '105', 'type': 'call', 'children': ['106', '111']},{'id': '106', 'type': 'attribute', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'remote_store'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'add_file'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113', '114']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'compress_hint'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'compress_hint'},{'id': '117', 'type': 'finally_clause', 'children': ['118']},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'if_statement', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '121', 'type': 'block', 'children': ['122']},{'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': 'lock'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '127', 'type': 'argument_list', 'children': []},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'versioned_name'}
def put_file(self, name, filename, to_local_store=True, to_remote_store=True, compress_hint=True): if not to_local_store and not to_remote_store: raise ValueError("Neither to_local_store nor to_remote_store set " "in a call to filetracker.Client.put_file") check_name(name) lock = None if self.local_store: lock = self.lock_manager.lock_for(name) lock.lock_exclusive() try: if (to_local_store or not self.remote_store) and self.local_store: versioned_name = self.local_store.add_file(name, filename) if (to_remote_store or not self.local_store) and self.remote_store: versioned_name = self.remote_store.add_file( name, filename, compress_hint=compress_hint) finally: if lock: lock.close() return versioned_name
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'operations'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'loud'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '17', '21', '25', '54', '165']},{'id': '9', 'type': 'if_statement', 'children': ['10', '12']},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'CHECKERS'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'load_checkers'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'roll_call'},{'id': '20', 'type': 'list', 'children': [], 'value': '[]'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'everything_ok'},{'id': '24', 'type': 'True', 'children': []},{'id': '25', 'type': 'if_statement', 'children': ['26', '29']},{'id': '26', 'type': 'boolean_operator', 'children': ['27', '28'], 'value': 'and'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'loud'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'operations'},{'id': '29', 'type': 'block', 'children': ['30', '34']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '33', 'type': 'string', 'children': [], 'value': '"Preflyt Checklist"'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': '"{}\\n{}\\n"'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '*'},{'id': '49', 'type': 'string', 'children': [], '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': 'title'},{'id': '54', 'type': 'for_statement', 'children': ['55', '56', '57']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'operations'},{'id': '57', 'type': 'block', 'children': ['58', '73', '81', '101', '109', '119', '127', '143']},{'id': '58', 'type': 'if_statement', 'children': ['59', '67']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '66'], 'value': 'not'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'string', 'children': [], 'value': "'checker'"},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'CHECKERS'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'raise_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'CheckerNotFoundError'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'checker_cls'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'CHECKERS'},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '80', 'type': 'string', 'children': [], 'value': "'checker'"},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '84', 'type': 'dictionary_comprehension', 'children': ['85', '88', '97']},{'id': '85', 'type': 'pair', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '88', 'type': 'for_in_clause', 'children': ['89', '92']},{'id': '89', 'type': 'pattern_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '96', 'type': 'argument_list', 'children': []},{'id': '97', 'type': 'if_clause', 'children': ['98']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': '!='},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '100', 'type': 'string', 'children': [], 'value': "'checker'"},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'checker'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'checker_cls'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'dictionary_splat', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '114']},{'id': '111', 'type': 'pattern_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'checker'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'if_statement', 'children': ['120', '122']},{'id': '120', 'type': 'not_operator', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'everything_ok'},{'id': '126', 'type': 'False', 'children': []},{'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': 'roll_call'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'dictionary', 'children': ['134', '137', '140']},{'id': '134', 'type': 'pair', 'children': ['135', '136']},{'id': '135', 'type': 'string', 'children': [], 'value': '"check"'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '137', 'type': 'pair', 'children': ['138', '139']},{'id': '138', 'type': 'string', 'children': [], 'value': '"success"'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '140', 'type': 'pair', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': '"message"'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '143', 'type': 'if_statement', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'loud'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '153']},{'id': '148', 'type': 'attribute', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'string', 'children': [], 'value': '" {}\\n"'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'pformat_check'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163', '164']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '165', 'type': 'return_statement', 'children': ['166']},{'id': '166', 'type': 'expression_list', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'everything_ok'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'roll_call'}
def check(operations, loud=False): if not CHECKERS: load_checkers() roll_call = [] everything_ok = True if loud and operations: title = "Preflyt Checklist" sys.stderr.write("{}\n{}\n".format(title, "=" * len(title))) for operation in operations: if operation.get('checker') not in CHECKERS: raise CheckerNotFoundError(operation) checker_cls = CHECKERS[operation['checker']] args = {k: v for k, v in operation.items() if k != 'checker'} checker = checker_cls(**args) success, message = checker.check() if not success: everything_ok = False roll_call.append({"check": operation, "success": success, "message": message}) if loud: sys.stderr.write(" {}\n".format(pformat_check(success, operation, message))) return everything_ok, roll_call
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'deci2sexa'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'deci'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'pre'},{'id': '7', 'type': 'integer', 'children': [], 'value': '3'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'trunc'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'upper_trim'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '49', '53', '70', '80', '92', '98', '104', '131', '138', '153', '166', '173', '180', '203', '220', '227']},{'id': '24', 'type': 'if_statement', 'children': ['25', '32']},{'id': '25', 'type': 'boolean_operator', 'children': ['26', '29'], 'value': 'and'},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'upper'},{'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': 'deci'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40', '43', '46']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'deci'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'if_statement', 'children': ['54', '57']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': '<'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'deci'},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'block', 'children': ['58', '65']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'deci'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'deci'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '68', 'type': 'unary_operator', 'children': ['69'], 'value': '-'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '75']},{'id': '72', 'type': 'pattern_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'hd'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'f1'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'divmod'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'deci'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'pattern_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'f2'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'divmod'},{'id': '87', 'type': 'argument_list', 'children': ['88', '91']},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '*'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'f1'},{'id': '90', 'type': 'float', 'children': [], 'value': '60.0'},{'id': '91', 'type': 'integer', 'children': [], 'value': '1'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'sf'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '*'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'f2'},{'id': '97', 'type': 'float', 'children': [], 'value': '60.0'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '**'},{'id': '102', 'type': 'integer', 'children': [], 'value': '10'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'pre'},{'id': '104', 'type': 'if_statement', 'children': ['105', '106', '119']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'trunc'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'pattern_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '111', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'divmod'},{'id': '114', 'type': 'argument_list', 'children': ['115', '118']},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '*'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'sf'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'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': 'ss'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '126', 'type': 'argument_list', 'children': ['127', '130']},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '*'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'sf'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '130', 'type': 'integer', 'children': [], 'value': '0'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '138', 'type': 'if_statement', 'children': ['139', '144']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '=='},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '*'},{'id': '142', 'type': 'integer', 'children': [], 'value': '60'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '144', 'type': 'block', 'children': ['145', '149']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'augmented_assignment', 'children': ['147', '148'], 'value': '+='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '148', 'type': 'integer', 'children': [], 'value': '1'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'if_statement', 'children': ['154', '157']},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': '=='},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '156', 'type': 'integer', 'children': [], 'value': '60'},{'id': '157', 'type': 'block', 'children': ['158', '162']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'augmented_assignment', 'children': ['160', '161'], 'value': '+='},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'hd'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '165', 'type': 'integer', 'children': [], 'value': '0'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'hd'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'hd'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '180', 'type': 'if_statement', 'children': ['181', '190']},{'id': '181', 'type': 'boolean_operator', 'children': ['182', '189'], 'value': 'and'},{'id': '182', 'type': 'boolean_operator', 'children': ['183', '186'], 'value': 'and'},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'is'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '185', 'type': 'None', 'children': []},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': 'is'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '188', 'type': 'None', 'children': []},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'upper_trim'},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'if_statement', 'children': ['192', '195']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '=='},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'hd'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'hd'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '203', 'type': 'if_statement', 'children': ['204', '215']},{'id': '204', 'type': 'boolean_operator', 'children': ['205', '212'], 'value': 'and'},{'id': '205', 'type': 'boolean_operator', 'children': ['206', '209'], 'value': 'and'},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': '=='},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'hd'},{'id': '208', 'type': 'integer', 'children': [], 'value': '0'},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '211'], 'value': '=='},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '211', 'type': 'integer', 'children': [], 'value': '0'},{'id': '212', 'type': 'comparison_operator', 'children': ['213', '214'], 'value': '=='},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '214', 'type': 'integer', 'children': [], 'value': '0'},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '219', 'type': 'integer', 'children': [], 'value': '1'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'augmented_assignment', 'children': ['222', '223'], 'value': '/='},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '227', 'type': 'return_statement', 'children': ['228']},{'id': '228', 'type': 'tuple', 'children': ['229', '230', '231', '232']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'hd'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'ss'}
def deci2sexa(deci, pre=3, trunc=False, lower=None, upper=None, b=False, upper_trim=False): if lower is not None and upper is not None: deci = normalize(deci, lower=lower, upper=upper, b=b) sign = 1 if deci < 0: deci = abs(deci) sign = -1 hd, f1 = divmod(deci, 1) mm, f2 = divmod(f1 * 60.0, 1) sf = f2 * 60.0 fp = 10 ** pre if trunc: ss, _ = divmod(sf * fp, 1) else: ss = round(sf * fp, 0) ss = int(ss) if ss == 60 * fp: mm += 1 ss = 0 if mm == 60: hd += 1 mm = 0 hd = int(hd) mm = int(mm) if lower is not None and upper is not None and upper_trim: if hd == upper: hd = int(lower) if hd == 0 and mm == 0 and ss == 0: sign = 1 ss /= float(fp) return (sign, hd, mm, ss)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'phmsdms'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'hmsdms'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '23', '32', '40', '49', '56', '129', '423', '451', '460', '476']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'pattern1'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': 'r"([-+]?[0-9]*\\.?[0-9]+[^0-9\\-+]*)"'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pattern2'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': 'r"([-+]?[0-9]*\\.?[0-9]+)"'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'hmsdms'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'hmsdms'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'hdlist'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'pattern1'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'hmsdms'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '52', 'type': 'list', 'children': ['53', '54', '55'], 'value': '[None, None, None]'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'function_definition', 'children': ['57', '58', '59']},{'id': '57', 'type': 'function_name', 'children': [], 'value': '_fill_right_not_none'},{'id': '58', 'type': 'parameters', 'children': []},{'id': '59', 'type': 'block', 'children': ['60', '67', '82']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'rp'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '67', 'type': 'for_statement', 'children': ['68', '71', '75']},{'id': '68', 'type': 'pattern_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'rp'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'if_statement', 'children': ['77', '80']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'is'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'break_statement', 'children': []},{'id': '82', 'type': 'if_statement', 'children': ['83', '86', '92', '103']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '=='},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '85', 'type': 'integer', 'children': [], 'value': '0'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'raise_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': '"Invalid string."'},{'id': '92', 'type': 'elif_clause', 'children': ['93', '96']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '=='},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '102']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '101', 'type': 'integer', 'children': [], 'value': '2'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '103', 'type': 'elif_clause', 'children': ['104', '107']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '=='},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '106', 'type': 'integer', 'children': [], 'value': '2'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'if_statement', 'children': ['109', '114', '121']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '113'], 'value': 'is'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'None', 'children': []},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '120']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '119', 'type': 'integer', 'children': [], 'value': '0'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '121', 'type': 'else_clause', 'children': ['122']},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '129', 'type': 'for_statement', 'children': ['130', '131', '132']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'hdlist'},{'id': '132', 'type': 'block', 'children': ['133', '415']},{'id': '133', 'type': 'try_statement', 'children': ['134', '146']},{'id': '134', 'type': 'block', 'children': ['135', '142']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': '_fill_right_not_none'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'except_clause', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '148', 'type': 'block', 'children': ['149', '193', '237', '277', '317', '353', '389']},{'id': '149', 'type': 'if_statement', 'children': ['150', '157']},{'id': '150', 'type': 'boolean_operator', 'children': ['151', '154'], 'value': 'or'},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'in'},{'id': '152', 'type': 'string', 'children': [], 'value': '"hh"'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'in'},{'id': '155', 'type': 'string', 'children': [], 'value': '"h"'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '157', 'type': 'block', 'children': ['158', '167', '189']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'pattern2'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '171', 'type': 'integer', 'children': [], 'value': '0'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '177', 'type': 'slice', 'children': ['178', '183', '184']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '182', 'type': 'argument_list', 'children': []},{'id': '183', 'type': 'colon', 'children': []},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '188', 'type': 'argument_list', 'children': []},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '192', 'type': 'string', 'children': [], 'value': '"hours"'},{'id': '193', 'type': 'if_statement', 'children': ['194', '201']},{'id': '194', 'type': 'boolean_operator', 'children': ['195', '198'], 'value': 'or'},{'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': 'in'},{'id': '196', 'type': 'string', 'children': [], 'value': '"dd"'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': 'in'},{'id': '199', 'type': 'string', 'children': [], 'value': '"d"'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '201', 'type': 'block', 'children': ['202', '211', '233']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'pattern2'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '216']},{'id': '213', 'type': 'subscript', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '215', 'type': 'integer', 'children': [], 'value': '0'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '221', 'type': 'slice', 'children': ['222', '227', '228']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '226', 'type': 'argument_list', 'children': []},{'id': '227', 'type': 'colon', 'children': []},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '232', 'type': 'argument_list', 'children': []},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '236', 'type': 'string', 'children': [], 'value': '"degrees"'},{'id': '237', 'type': 'if_statement', 'children': ['238', '245']},{'id': '238', 'type': 'boolean_operator', 'children': ['239', '242'], 'value': 'or'},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': 'in'},{'id': '240', 'type': 'string', 'children': [], 'value': '"mm"'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': 'in'},{'id': '243', 'type': 'string', 'children': [], 'value': '"m"'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '245', 'type': 'block', 'children': ['246', '255']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'pattern2'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '260']},{'id': '257', 'type': 'subscript', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '259', 'type': 'integer', 'children': [], 'value': '1'},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '265', 'type': 'slice', 'children': ['266', '271', '272']},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '270', 'type': 'argument_list', 'children': []},{'id': '271', 'type': 'colon', 'children': []},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '276', 'type': 'argument_list', 'children': []},{'id': '277', 'type': 'if_statement', 'children': ['278', '285']},{'id': '278', 'type': 'boolean_operator', 'children': ['279', '282'], 'value': 'or'},{'id': '279', 'type': 'comparison_operator', 'children': ['280', '281'], 'value': 'in'},{'id': '280', 'type': 'string', 'children': [], 'value': '"ss"'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '282', 'type': 'comparison_operator', 'children': ['283', '284'], 'value': 'in'},{'id': '283', 'type': 'string', 'children': [], 'value': '"s"'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '285', 'type': 'block', 'children': ['286', '295']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'pattern2'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '300']},{'id': '297', 'type': 'subscript', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '299', 'type': 'integer', 'children': [], 'value': '2'},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '305', 'type': 'slice', 'children': ['306', '311', '312']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '310', 'type': 'argument_list', 'children': []},{'id': '311', 'type': 'colon', 'children': []},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '316', 'type': 'argument_list', 'children': []},{'id': '317', 'type': 'if_statement', 'children': ['318', '321']},{'id': '318', 'type': 'comparison_operator', 'children': ['319', '320'], 'value': 'in'},{'id': '319', 'type': 'string', 'children': [], 'value': '"\'"'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '321', 'type': 'block', 'children': ['322', '331']},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'assignment', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '325', 'type': 'call', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'pattern2'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'assignment', 'children': ['333', '336']},{'id': '333', 'type': 'subscript', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '335', 'type': 'integer', 'children': [], 'value': '1'},{'id': '336', 'type': 'call', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'subscript', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '341', 'type': 'slice', 'children': ['342', '347', '348']},{'id': '342', 'type': 'call', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '346', 'type': 'argument_list', 'children': []},{'id': '347', 'type': 'colon', 'children': []},{'id': '348', 'type': 'call', 'children': ['349', '352']},{'id': '349', 'type': 'attribute', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '352', 'type': 'argument_list', 'children': []},{'id': '353', 'type': 'if_statement', 'children': ['354', '357']},{'id': '354', 'type': 'comparison_operator', 'children': ['355', '356'], 'value': 'in'},{'id': '355', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '357', 'type': 'block', 'children': ['358', '367']},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'assignment', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '361', 'type': 'call', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'pattern2'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '365', 'type': 'argument_list', 'children': ['366']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '367', 'type': 'expression_statement', 'children': ['368']},{'id': '368', 'type': 'assignment', 'children': ['369', '372']},{'id': '369', 'type': 'subscript', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '371', 'type': 'integer', 'children': [], 'value': '2'},{'id': '372', 'type': 'call', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '374', 'type': 'argument_list', 'children': ['375']},{'id': '375', 'type': 'subscript', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '377', 'type': 'slice', 'children': ['378', '383', '384']},{'id': '378', 'type': 'call', 'children': ['379', '382']},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '382', 'type': 'argument_list', 'children': []},{'id': '383', 'type': 'colon', 'children': []},{'id': '384', 'type': 'call', 'children': ['385', '388']},{'id': '385', 'type': 'attribute', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '388', 'type': 'argument_list', 'children': []},{'id': '389', 'type': 'if_statement', 'children': ['390', '393']},{'id': '390', 'type': 'comparison_operator', 'children': ['391', '392'], 'value': 'in'},{'id': '391', 'type': 'string', 'children': [], 'value': '":"'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '393', 'type': 'block', 'children': ['394', '404', '411']},{'id': '394', 'type': 'expression_statement', 'children': ['395']},{'id': '395', 'type': 'assignment', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '397', 'type': 'call', 'children': ['398', '401']},{'id': '398', 'type': 'attribute', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'valun'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '401', 'type': 'argument_list', 'children': ['402', '403']},{'id': '402', 'type': 'string', 'children': [], 'value': '":"'},{'id': '403', 'type': 'string', 'children': [], 'value': '""'},{'id': '404', 'type': 'expression_statement', 'children': ['405']},{'id': '405', 'type': 'assignment', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '407', 'type': 'call', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '409', 'type': 'argument_list', 'children': ['410']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '411', 'type': 'expression_statement', 'children': ['412']},{'id': '412', 'type': 'call', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': '_fill_right_not_none'},{'id': '414', 'type': 'argument_list', 'children': []},{'id': '415', 'type': 'if_statement', 'children': ['416', '418']},{'id': '416', 'type': 'not_operator', 'children': ['417']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '418', 'type': 'block', 'children': ['419']},{'id': '419', 'type': 'expression_statement', 'children': ['420']},{'id': '420', 'type': 'assignment', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '422', 'type': 'string', 'children': [], 'value': '"degrees"'},{'id': '423', 'type': 'for_statement', 'children': ['424', '425', '426']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '426', 'type': 'block', 'children': ['427']},{'id': '427', 'type': 'if_statement', 'children': ['428', '433']},{'id': '428', 'type': 'boolean_operator', 'children': ['429', '430'], 'value': 'and'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '430', 'type': 'comparison_operator', 'children': ['431', '432'], 'value': '<'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '432', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '433', 'type': 'block', 'children': ['434']},{'id': '434', 'type': 'if_statement', 'children': ['435', '438', '444']},{'id': '435', 'type': 'comparison_operator', 'children': ['436', '437'], 'value': 'is'},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '437', 'type': 'None', 'children': []},{'id': '438', 'type': 'block', 'children': ['439']},{'id': '439', 'type': 'expression_statement', 'children': ['440']},{'id': '440', 'type': 'assignment', 'children': ['441', '442']},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '442', 'type': 'unary_operator', 'children': ['443'], 'value': '-'},{'id': '443', 'type': 'integer', 'children': [], 'value': '1'},{'id': '444', 'type': 'else_clause', 'children': ['445']},{'id': '445', 'type': 'block', 'children': ['446']},{'id': '446', 'type': 'raise_statement', 'children': ['447']},{'id': '447', 'type': 'call', 'children': ['448', '449']},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '449', 'type': 'argument_list', 'children': ['450']},{'id': '450', 'type': 'string', 'children': [], 'value': '"Only one number can be negative."'},{'id': '451', 'type': 'if_statement', 'children': ['452', '455']},{'id': '452', 'type': 'comparison_operator', 'children': ['453', '454'], 'value': 'is'},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '454', 'type': 'None', 'children': []},{'id': '455', 'type': 'block', 'children': ['456']},{'id': '456', 'type': 'expression_statement', 'children': ['457']},{'id': '457', 'type': 'assignment', 'children': ['458', '459']},{'id': '458', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '459', 'type': 'integer', 'children': [], 'value': '1'},{'id': '460', 'type': 'expression_statement', 'children': ['461']},{'id': '461', 'type': 'assignment', 'children': ['462', '463']},{'id': '462', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '463', 'type': 'list_comprehension', 'children': ['464', '473']},{'id': '464', 'type': 'conditional_expression', 'children': ['465', '469', '472'], 'value': 'if'},{'id': '465', 'type': 'call', 'children': ['466', '467']},{'id': '466', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '467', 'type': 'argument_list', 'children': ['468']},{'id': '468', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '469', 'type': 'comparison_operator', 'children': ['470', '471'], 'value': 'is'},{'id': '470', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '471', 'type': 'None', 'children': []},{'id': '472', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '473', 'type': 'for_in_clause', 'children': ['474', '475']},{'id': '474', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '475', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '476', 'type': 'return_statement', 'children': ['477']},{'id': '477', 'type': 'call', 'children': ['478', '479']},{'id': '478', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '479', 'type': 'argument_list', 'children': ['480', '483', '486', '489']},{'id': '480', 'type': 'keyword_argument', 'children': ['481', '482']},{'id': '481', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '482', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '483', 'type': 'keyword_argument', 'children': ['484', '485']},{'id': '484', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '485', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '486', 'type': 'keyword_argument', 'children': ['487', '488']},{'id': '487', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '488', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '489', 'type': 'keyword_argument', 'children': ['490', '491']},{'id': '490', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '491', 'type': 'identifier', 'children': [], 'value': 'parts'}
def phmsdms(hmsdms): units = None sign = None pattern1 = re.compile(r"([-+]?[0-9]*\.?[0-9]+[^0-9\-+]*)") pattern2 = re.compile(r"([-+]?[0-9]*\.?[0-9]+)") hmsdms = hmsdms.lower() hdlist = pattern1.findall(hmsdms) parts = [None, None, None] def _fill_right_not_none(): rp = reversed(parts) for i, j in enumerate(rp): if j is not None: break if i == 0: raise ValueError("Invalid string.") elif i == 1: parts[2] = v elif i == 2: if parts[0] is None: parts[0] = v else: parts[1] = v for valun in hdlist: try: v = float(valun) _fill_right_not_none() except ValueError: if "hh" in valun or "h" in valun: m = pattern2.search(valun) parts[0] = float(valun[m.start():m.end()]) units = "hours" if "dd" in valun or "d" in valun: m = pattern2.search(valun) parts[0] = float(valun[m.start():m.end()]) units = "degrees" if "mm" in valun or "m" in valun: m = pattern2.search(valun) parts[1] = float(valun[m.start():m.end()]) if "ss" in valun or "s" in valun: m = pattern2.search(valun) parts[2] = float(valun[m.start():m.end()]) if "'" in valun: m = pattern2.search(valun) parts[1] = float(valun[m.start():m.end()]) if '"' in valun: m = pattern2.search(valun) parts[2] = float(valun[m.start():m.end()]) if ":" in valun: v = valun.replace(":", "") v = float(v) _fill_right_not_none() if not units: units = "degrees" for i in parts: if i and i < 0.0: if sign is None: sign = -1 else: raise ValueError("Only one number can be negative.") if sign is None: sign = 1 vals = [abs(i) if i is not None else 0.0 for i in parts] return dict(sign=sign, units=units, vals=vals, parts=parts)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pposition'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'hd'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '19', '34', '160', '192']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': 'r"[^\\d\\-+.]*"'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'hd'},{'id': '19', 'type': 'if_statement', 'children': ['20', '28']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': 'not'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '25', 'type': 'list', 'children': ['26', '27'], 'value': '[2, 6]'},{'id': '26', 'type': 'integer', 'children': [], 'value': '2'},{'id': '27', 'type': 'integer', 'children': [], 'value': '6'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'raise_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'string', 'children': [], 'value': '"Input must contain either 2 or 6 numbers."'},{'id': '34', 'type': 'if_statement', 'children': ['35', '41', '79']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '40'], 'value': '=='},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '40', 'type': 'integer', 'children': [], 'value': '2'},{'id': '41', 'type': 'block', 'children': ['42', '60']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '47']},{'id': '44', 'type': 'pattern_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '47', 'type': 'expression_list', 'children': ['48', '54']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'if_statement', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '62', 'type': 'block', 'children': ['63', '67', '73']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'numvals'},{'id': '66', 'type': 'integer', 'children': [], 'value': '2'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'raw_x'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'raw_y'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'elif_clause', 'children': ['80', '86']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '85'], 'value': '=='},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '85', 'type': 'integer', 'children': [], 'value': '6'},{'id': '86', 'type': 'block', 'children': ['87', '103', '116', '132', '145']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'x_p'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'phmsdms'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': '" "'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '100', 'type': 'slice', 'children': ['101', '102']},{'id': '101', 'type': 'colon', 'children': []},{'id': '102', 'type': 'integer', 'children': [], 'value': '3'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sexa2deci'},{'id': '108', 'type': 'argument_list', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'x_p'},{'id': '111', 'type': 'string', 'children': [], 'value': "'sign'"},{'id': '112', 'type': 'list_splat', 'children': ['113']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'x_p'},{'id': '115', 'type': 'string', 'children': [], 'value': "'vals'"},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'y_p'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'phmsdms'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'string', 'children': [], 'value': '" "'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '129', 'type': 'slice', 'children': ['130', '131']},{'id': '130', 'type': 'integer', 'children': [], 'value': '3'},{'id': '131', 'type': 'colon', 'children': []},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'sexa2deci'},{'id': '137', 'type': 'argument_list', 'children': ['138', '141']},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'y_p'},{'id': '140', 'type': 'string', 'children': [], 'value': "'sign'"},{'id': '141', 'type': 'list_splat', 'children': ['142']},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'y_p'},{'id': '144', 'type': 'string', 'children': [], 'value': "'vals'"},{'id': '145', 'type': 'if_statement', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '147', 'type': 'block', 'children': ['148', '152', '156']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'raw_x'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'x_p'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'raw_y'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'y_p'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'numvals'},{'id': '159', 'type': 'integer', 'children': [], 'value': '6'},{'id': '160', 'type': 'if_statement', 'children': ['161', '162', '184']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '168', 'type': 'argument_list', 'children': ['169', '172', '175', '178', '181']},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'numvals'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'numvals'},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'raw_x'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'raw_x'},{'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'raw_y'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'raw_y'},{'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': 'result'},{'id': '189', 'type': 'expression_list', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '192', 'type': 'return_statement', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'result'}
def pposition(hd, details=False): p = re.split(r"[^\d\-+.]*", hd) if len(p) not in [2, 6]: raise ValueError("Input must contain either 2 or 6 numbers.") if len(p) == 2: x, y = float(p[0]), float(p[1]) if details: numvals = 2 raw_x = p[0] raw_y = p[1] elif len(p) == 6: x_p = phmsdms(" ".join(p[:3])) x = sexa2deci(x_p['sign'], *x_p['vals']) y_p = phmsdms(" ".join(p[3:])) y = sexa2deci(y_p['sign'], *y_p['vals']) if details: raw_x = x_p raw_y = y_p numvals = 6 if details: result = dict(x=x, y=y, numvals=numvals, raw_x=raw_x, raw_y=raw_y) else: result = x, y return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '68']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'Create'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41', '44', '47', '50', '53', '56', '59', '62', '65']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'network_id'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ip_address'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '25', 'type': 'string', 'children': [], 'value': '"standard"'},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '28', 'type': 'string', 'children': [], 'value': '"standard"'},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'primary_dns'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'secondary_dns'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'additional_disks'},{'id': '37', 'type': 'list', 'children': [], 'value': '[]'},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'custom_fields'},{'id': '40', 'type': 'list', 'children': [], 'value': '[]'},{'id': '41', 'type': 'default_parameter', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'default_parameter', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'managed_os'},{'id': '46', 'type': 'False', 'children': []},{'id': '47', 'type': 'default_parameter', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '49', 'type': 'None', 'children': []},{'id': '50', 'type': 'default_parameter', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'source_server_password'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'default_parameter', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'cpu_autoscale_policy_id'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'default_parameter', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'anti_affinity_policy_id'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'default_parameter', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '61', 'type': 'list', 'children': [], 'value': '[]'},{'id': '62', 'type': 'default_parameter', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'configuration_id'},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'default_parameter', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'block', 'children': ['69', '88', '96', '195', '222', '247', '260', '275', '300', '331', '394']},{'id': '69', 'type': 'if_statement', 'children': ['70', '72']},{'id': '70', 'type': 'not_operator', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '76', 'type': 'call', 'children': ['77', '84']},{'id': '77', 'type': 'attribute', 'children': ['78', '83']},{'id': '78', 'type': 'attribute', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'v2'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'Account'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'GetAlias'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '88', 'type': 'if_statement', 'children': ['89', '91']},{'id': '89', 'type': 'not_operator', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '96', 'type': 'if_statement', 'children': ['97', '104']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '103'], 'value': '!='},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'string', 'children': [], 'value': '"baremetal"'},{'id': '104', 'type': 'block', 'children': ['105', '131', '163']},{'id': '105', 'type': 'if_statement', 'children': ['106', '111']},{'id': '106', 'type': 'boolean_operator', 'children': ['107', '109'], 'value': 'or'},{'id': '107', 'type': 'not_operator', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '109', 'type': 'not_operator', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'group'},{'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': 'clc'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'v2'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'Group'},{'id': '121', 'type': 'argument_list', 'children': ['122', '125', '128']},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '131', 'type': 'if_statement', 'children': ['132', '141', '151']},{'id': '132', 'type': 'boolean_operator', 'children': ['133', '135'], 'value': 'and'},{'id': '133', 'type': 'not_operator', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'Defaults'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'string', 'children': [], 'value': '"cpu"'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'Defaults'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'string', 'children': [], 'value': '"cpu"'},{'id': '151', 'type': 'elif_clause', 'children': ['152', '154']},{'id': '152', 'type': 'not_operator', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'raise_statement', 'children': ['156']},{'id': '156', 'type': '()', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'CLCException'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'string', 'children': [], 'value': '"No default CPU defined"'},{'id': '163', 'type': 'if_statement', 'children': ['164', '173', '183']},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '167'], 'value': 'and'},{'id': '165', 'type': 'not_operator', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'Defaults'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'string', 'children': [], 'value': '"memory"'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'Defaults'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'string', 'children': [], 'value': '"memory"'},{'id': '183', 'type': 'elif_clause', 'children': ['184', '186']},{'id': '184', 'type': 'not_operator', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'raise_statement', 'children': ['188']},{'id': '188', 'type': '()', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'CLCException'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'string', 'children': [], 'value': '"No default Memory defined"'},{'id': '195', 'type': 'if_statement', 'children': ['196', '213']},{'id': '196', 'type': 'boolean_operator', 'children': ['197', '204'], 'value': 'and'},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '203'], 'value': '=='},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '202', 'type': 'argument_list', 'children': []},{'id': '203', 'type': 'string', 'children': [], 'value': '"standard"'},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '210'], 'value': 'not'},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'tuple', 'children': ['211', '212']},{'id': '211', 'type': 'string', 'children': [], 'value': '"standard"'},{'id': '212', 'type': 'string', 'children': [], 'value': '"premium"'},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'raise_statement', 'children': ['215']},{'id': '215', 'type': '()', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'CLCException'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'string', 'children': [], 'value': '"Invalid type/storage_type combo"'},{'id': '222', 'type': 'if_statement', 'children': ['223', '238']},{'id': '223', 'type': 'boolean_operator', 'children': ['224', '231'], 'value': 'and'},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '230'], 'value': '=='},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '229', 'type': 'argument_list', 'children': []},{'id': '230', 'type': 'string', 'children': [], 'value': '"hyperscale"'},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '237'], 'value': '!='},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '236', 'type': 'argument_list', 'children': []},{'id': '237', 'type': 'string', 'children': [], 'value': '"hyperscale"'},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'raise_statement', 'children': ['240']},{'id': '240', 'type': '()', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'CLCException'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'string', 'children': [], 'value': '"Invalid type/storage_type combo"'},{'id': '247', 'type': 'if_statement', 'children': ['248', '255']},{'id': '248', 'type': 'comparison_operator', 'children': ['249', '254'], 'value': '=='},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '253', 'type': 'argument_list', 'children': []},{'id': '254', 'type': 'string', 'children': [], 'value': '"baremetal"'},{'id': '255', 'type': 'block', 'children': ['256']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '259', 'type': 'string', 'children': [], 'value': '"bareMetal"'},{'id': '260', 'type': 'if_statement', 'children': ['261', '266']},{'id': '261', 'type': 'boolean_operator', 'children': ['262', '263'], 'value': 'and'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '263', 'type': 'comparison_operator', 'children': ['264', '265'], 'value': '<='},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '265', 'type': 'integer', 'children': [], 'value': '3600'},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'raise_statement', 'children': ['268']},{'id': '268', 'type': '()', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'CLCException'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'string', 'children': [], 'value': '"ttl must be greater than 3600 seconds"'},{'id': '275', 'type': 'if_statement', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '281', 'type': 'call', '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': 'clc'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'v2'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'time_utils'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'SecondsToZuluTS'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'binary_operator', 'children': ['291', '299'], 'value': '+'},{'id': '291', 'type': 'call', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '298', 'type': 'argument_list', 'children': []},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '303', 'type': 'dictionary', 'children': ['304', '307', '310', '313', '316', '319', '322', '325', '328']},{'id': '304', 'type': 'pair', 'children': ['305', '306']},{'id': '305', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '307', 'type': 'pair', 'children': ['308', '309']},{'id': '308', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '310', 'type': 'pair', 'children': ['311', '312']},{'id': '311', 'type': 'string', 'children': [], 'value': "'groupId'"},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '313', 'type': 'pair', 'children': ['314', '315']},{'id': '314', 'type': 'string', 'children': [], 'value': "'primaryDNS'"},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'primary_dns'},{'id': '316', 'type': 'pair', 'children': ['317', '318']},{'id': '317', 'type': 'string', 'children': [], 'value': "'secondaryDNS'"},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'secondary_dns'},{'id': '319', 'type': 'pair', 'children': ['320', '321']},{'id': '320', 'type': 'string', 'children': [], 'value': "'networkId'"},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'network_id'},{'id': '322', 'type': 'pair', 'children': ['323', '324']},{'id': '323', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '325', 'type': 'pair', 'children': ['326', '327']},{'id': '326', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '328', 'type': 'pair', 'children': ['329', '330']},{'id': '329', 'type': 'string', 'children': [], 'value': "'customFields'"},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'custom_fields'},{'id': '331', 'type': 'if_statement', 'children': ['332', '335', '349']},{'id': '332', 'type': 'comparison_operator', 'children': ['333', '334'], 'value': '=='},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '334', 'type': 'string', 'children': [], 'value': "'bareMetal'"},{'id': '335', 'type': 'block', 'children': ['336']},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'call', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'dictionary', 'children': ['343', '346']},{'id': '343', 'type': 'pair', 'children': ['344', '345']},{'id': '344', 'type': 'string', 'children': [], 'value': "'configurationId'"},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'configuration_id'},{'id': '346', 'type': 'pair', 'children': ['347', '348']},{'id': '347', 'type': 'string', 'children': [], 'value': "'osType'"},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '349', 'type': 'else_clause', 'children': ['350']},{'id': '350', 'type': 'block', 'children': ['351']},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': 'dictionary', 'children': ['358', '361', '364', '367', '370', '373', '376', '379', '382', '385', '388', '391']},{'id': '358', 'type': 'pair', 'children': ['359', '360']},{'id': '359', 'type': 'string', 'children': [], 'value': "'sourceServerId'"},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '361', 'type': 'pair', 'children': ['362', '363']},{'id': '362', 'type': 'string', 'children': [], 'value': "'isManagedOS'"},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'managed_os'},{'id': '364', 'type': 'pair', 'children': ['365', '366']},{'id': '365', 'type': 'string', 'children': [], 'value': "'ipAddress'"},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'ip_address'},{'id': '367', 'type': 'pair', 'children': ['368', '369']},{'id': '368', 'type': 'string', 'children': [], 'value': "'sourceServerPassword'"},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'source_server_password'},{'id': '370', 'type': 'pair', 'children': ['371', '372']},{'id': '371', 'type': 'string', 'children': [], 'value': "'cpu'"},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '373', 'type': 'pair', 'children': ['374', '375']},{'id': '374', 'type': 'string', 'children': [], 'value': "'cpuAutoscalePolicyId'"},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'cpu_autoscale_policy_id'},{'id': '376', 'type': 'pair', 'children': ['377', '378']},{'id': '377', 'type': 'string', 'children': [], 'value': "'memoryGB'"},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '379', 'type': 'pair', 'children': ['380', '381']},{'id': '380', 'type': 'string', 'children': [], 'value': "'storageType'"},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '382', 'type': 'pair', 'children': ['383', '384']},{'id': '383', 'type': 'string', 'children': [], 'value': "'antiAffinityPolicyId'"},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'anti_affinity_policy_id'},{'id': '385', 'type': 'pair', 'children': ['386', '387']},{'id': '386', 'type': 'string', 'children': [], 'value': "'additionalDisks'"},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'additional_disks'},{'id': '388', 'type': 'pair', 'children': ['389', '390']},{'id': '389', 'type': 'string', 'children': [], 'value': "'ttl'"},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '391', 'type': 'pair', 'children': ['392', '393']},{'id': '392', 'type': 'string', 'children': [], 'value': "'packages'"},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '394', 'type': 'return_statement', 'children': ['395']},{'id': '395', 'type': 'call', 'children': ['396', '401']},{'id': '396', 'type': 'attribute', 'children': ['397', '400']},{'id': '397', 'type': 'attribute', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'v2'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'Requests'},{'id': '401', 'type': 'argument_list', 'children': ['402', '425', '428']},{'id': '402', 'type': 'call', 'children': ['403', '410']},{'id': '403', 'type': 'attribute', 'children': ['404', '409']},{'id': '404', 'type': 'attribute', 'children': ['405', '408']},{'id': '405', 'type': 'attribute', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'v2'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'API'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'Call'},{'id': '410', 'type': 'argument_list', 'children': ['411', '412', '416', '422']},{'id': '411', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '412', 'type': 'binary_operator', 'children': ['413', '414'], 'value': '%'},{'id': '413', 'type': 'string', 'children': [], 'value': "'servers/%s'"},{'id': '414', 'type': '()', 'children': ['415']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '416', 'type': 'call', 'children': ['417', '420']},{'id': '417', 'type': 'attribute', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '420', 'type': 'argument_list', 'children': ['421']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '422', 'type': 'keyword_argument', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '425', 'type': 'keyword_argument', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '428', 'type': 'keyword_argument', 'children': ['429', '430']},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'session'}
def Create(name,template,group_id,network_id,cpu=None,memory=None,alias=None,password=None,ip_address=None, storage_type="standard",type="standard",primary_dns=None,secondary_dns=None, additional_disks=[],custom_fields=[],ttl=None,managed_os=False,description=None, source_server_password=None,cpu_autoscale_policy_id=None,anti_affinity_policy_id=None, packages=[],configuration_id=None,session=None): if not alias: alias = clc.v2.Account.GetAlias(session=session) if not description: description = name if type.lower() != "baremetal": if not cpu or not memory: group = clc.v2.Group(id=group_id,alias=alias,session=session) if not cpu and group.Defaults("cpu"): cpu = group.Defaults("cpu") elif not cpu: raise(clc.CLCException("No default CPU defined")) if not memory and group.Defaults("memory"): memory = group.Defaults("memory") elif not memory: raise(clc.CLCException("No default Memory defined")) if type.lower() == "standard" and storage_type.lower() not in ("standard","premium"): raise(clc.CLCException("Invalid type/storage_type combo")) if type.lower() == "hyperscale" and storage_type.lower() != "hyperscale": raise(clc.CLCException("Invalid type/storage_type combo")) if type.lower() == "baremetal": type = "bareMetal" if ttl and ttl<=3600: raise(clc.CLCException("ttl must be greater than 3600 seconds")) if ttl: ttl = clc.v2.time_utils.SecondsToZuluTS(int(time.time())+ttl) payload = { 'name': name, 'description': description, 'groupId': group_id, 'primaryDNS': primary_dns, 'secondaryDNS': secondary_dns, 'networkId': network_id, 'password': password, 'type': type, 'customFields': custom_fields } if type == 'bareMetal': payload.update({'configurationId': configuration_id, 'osType': template}) else: payload.update({'sourceServerId': template, 'isManagedOS': managed_os, 'ipAddress': ip_address, 'sourceServerPassword': source_server_password, 'cpu': cpu, 'cpuAutoscalePolicyId': cpu_autoscale_policy_id, 'memoryGB': memory, 'storageType': storage_type, 'antiAffinityPolicyId': anti_affinity_policy_id, 'additionalDisks': additional_disks, 'ttl': ttl, 'packages': packages}) return clc.v2.Requests(clc.v2.API.Call('POST','servers/%s' % (alias), json.dumps(payload), session=session), alias=alias, session=session)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '66']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'Clone'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33', '36', '39', '42', '45', '48', '51', '54', '57', '60', '63']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'network_id'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ip_address'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'default_parameter', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'primary_dns'},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'default_parameter', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'secondary_dns'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'default_parameter', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'custom_fields'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'default_parameter', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'default_parameter', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'managed_os'},{'id': '47', 'type': 'False', 'children': []},{'id': '48', 'type': 'default_parameter', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'default_parameter', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'source_server_password'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'default_parameter', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'cpu_autoscale_policy_id'},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'default_parameter', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'anti_affinity_policy_id'},{'id': '59', 'type': 'None', 'children': []},{'id': '60', 'type': 'default_parameter', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '62', 'type': 'list', 'children': [], 'value': '[]'},{'id': '63', 'type': 'default_parameter', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '65', 'type': 'integer', 'children': [], 'value': '1'},{'id': '66', 'type': 'block', 'children': ['67', '92', '102', '112', '122', '132', '146', '154', '164', '174', '184', '201', '211', '215', '307']},{'id': '67', 'type': 'if_statement', 'children': ['68', '70']},{'id': '68', 'type': 'not_operator', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'name'},{'id': '74', 'type': 'call', 'children': ['75', '90']},{'id': '75', 'type': 'attribute', 'children': ['76', '89']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '80', 'type': 'argument_list', 'children': ['81', '86']},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '%'},{'id': '82', 'type': 'string', 'children': [], 'value': '"%s(.+)\\d{2}$"'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'integer', 'children': [], 'value': '1'},{'id': '92', 'type': 'if_statement', 'children': ['93', '95']},{'id': '93', 'type': 'not_operator', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '102', 'type': 'if_statement', 'children': ['103', '105']},{'id': '103', 'type': 'not_operator', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '112', 'type': 'if_statement', 'children': ['113', '115']},{'id': '113', 'type': 'not_operator', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'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': 'group_id'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '122', 'type': 'if_statement', 'children': ['123', '125']},{'id': '123', 'type': 'not_operator', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '132', 'type': 'if_statement', 'children': ['133', '135']},{'id': '133', 'type': 'not_operator', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'source_server_password'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'source_server_password'},{'id': '139', 'type': 'subscript', 'children': ['140', '145']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'Credentials'},{'id': '144', 'type': 'argument_list', 'children': []},{'id': '145', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '146', 'type': 'if_statement', 'children': ['147', '149']},{'id': '147', 'type': 'not_operator', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'source_server_password'},{'id': '154', 'type': 'if_statement', 'children': ['155', '157']},{'id': '155', 'type': 'not_operator', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '164', 'type': 'if_statement', 'children': ['165', '167']},{'id': '165', 'type': 'not_operator', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '174', 'type': 'if_statement', 'children': ['175', '177']},{'id': '175', 'type': 'not_operator', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '184', 'type': 'if_statement', 'children': ['185', '194']},{'id': '185', 'type': 'boolean_operator', 'children': ['186', '188'], 'value': 'and'},{'id': '186', 'type': 'not_operator', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'custom_fields'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'custom_fields'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'custom_fields'},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'custom_fields'},{'id': '201', 'type': 'if_statement', 'children': ['202', '204']},{'id': '202', 'type': 'not_operator', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'requests_lst'},{'id': '214', 'type': 'list', 'children': [], 'value': '[]'},{'id': '215', 'type': 'for_statement', 'children': ['216', '217', '222']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221']},{'id': '220', 'type': 'integer', 'children': [], 'value': '0'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'requests_lst'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'Server'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'Create'},{'id': '233', 'type': 'argument_list', 'children': ['234', '235', '238', '241', '244', '247', '250', '255', '258', '261', '264', '267', '270', '273', '276', '279', '282', '285', '288', '291', '294', '297', '302']},{'id': '234', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '241', 'type': 'keyword_argument', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'network_id'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'network_id'},{'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'ip_address'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'ip_address'},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'storage_type'},{'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'primary_dns'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'primary_dns'},{'id': '270', 'type': 'keyword_argument', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'secondary_dns'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'secondary_dns'},{'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'custom_fields'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'custom_fields'},{'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '279', 'type': 'keyword_argument', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'managed_os'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'managed_os'},{'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '285', 'type': 'keyword_argument', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'source_server_password'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'source_server_password'},{'id': '288', 'type': 'keyword_argument', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'cpu_autoscale_policy_id'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'cpu_autoscale_policy_id'},{'id': '291', 'type': 'keyword_argument', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'anti_affinity_policy_id'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'anti_affinity_policy_id'},{'id': '294', 'type': 'keyword_argument', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'packages'},{'id': '297', 'type': 'keyword_argument', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '307', 'type': 'return_statement', 'children': ['308']},{'id': '308', 'type': '()', 'children': ['309']},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'requests_lst'}
def Clone(self,network_id,name=None,cpu=None,memory=None,group_id=None,alias=None,password=None,ip_address=None, storage_type=None,type=None,primary_dns=None,secondary_dns=None, custom_fields=None,ttl=None,managed_os=False,description=None, source_server_password=None,cpu_autoscale_policy_id=None,anti_affinity_policy_id=None, packages=[],count=1): if not name: name = re.search("%s(.+)\d{2}$" % self.alias,self.name).group(1) if not cpu: cpu = self.cpu if not memory: memory = self.memory if not group_id: group_id = self.group_id if not alias: alias = self.alias if not source_server_password: source_server_password = self.Credentials()['password'] if not password: password = source_server_password if not storage_type: storage_type = self.storage_type if not type: type = self.type if not storage_type: storage_type = self.storage_type if not custom_fields and len(self.custom_fields): custom_fields = self.custom_fields if not description: description = self.description requests_lst = [] for i in range(0,count): requests_lst.append(Server.Create( \ name=name,cpu=cpu,memory=memory,group_id=group_id,network_id=network_id,alias=self.alias, password=password,ip_address=ip_address,storage_type=storage_type,type=type, primary_dns=primary_dns,secondary_dns=secondary_dns, custom_fields=custom_fields,ttl=ttl,managed_os=managed_os,description=description, source_server_password=source_server_password,cpu_autoscale_policy_id=cpu_autoscale_policy_id, anti_affinity_policy_id=anti_affinity_policy_id,packages=packages, template=self.id,session=self.session)) return(sum(requests_lst))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'Call'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '59', '68', '101', '115', '140', '189', '222']},{'id': '16', 'type': 'if_statement', 'children': ['17', '20', '33']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '27']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '26', 'type': 'string', 'children': [], 'value': "'token'"},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'http_session'},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '32', 'type': 'string', 'children': [], 'value': "'http_session'"},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'id': '34', 'type': 'block', 'children': ['35', '47', '53']},{'id': '35', 'type': 'if_statement', 'children': ['36', '40']},{'id': '36', 'type': 'not_operator', 'children': ['37']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_LOGIN_TOKEN_V2'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'API'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_Login'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_LOGIN_TOKEN_V2'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'http_session'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_REQUESTS_SESSION'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '67', 'type': 'dictionary', 'children': []},{'id': '68', 'type': 'if_statement', 'children': ['69', '74', '87']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': '=='},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'fq_url'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '%'},{'id': '79', 'type': 'string', 'children': [], 'value': '"%s%s"'},{'id': '80', 'type': 'tuple', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ENDPOINT_URL_V2'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '87', 'type': 'else_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'fq_url'},{'id': '92', 'type': 'binary_operator', 'children': ['93', '94'], 'value': '%'},{'id': '93', 'type': 'string', 'children': [], 'value': '"%s/v2/%s"'},{'id': '94', 'type': 'tuple', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ENDPOINT_URL_V2'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'http_session'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'dictionary', 'children': ['110']},{'id': '110', 'type': 'pair', 'children': ['111', '112']},{'id': '111', 'type': 'string', 'children': [], 'value': "'Authorization'"},{'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '%'},{'id': '113', 'type': 'string', 'children': [], 'value': '"Bearer %s"'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '115', 'type': 'if_statement', 'children': ['116', '121', '130']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '129']},{'id': '124', 'type': 'subscript', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'http_session'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '128', 'type': 'string', 'children': [], 'value': "'content-type'"},{'id': '129', 'type': 'string', 'children': [], 'value': '"Application/json"'},{'id': '130', 'type': 'else_clause', 'children': ['131']},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '139']},{'id': '134', 'type': 'subscript', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'http_session'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '138', 'type': 'string', 'children': [], 'value': "'content-type'"},{'id': '139', 'type': 'string', 'children': [], 'value': '"application/x-www-form-urlencoded"'},{'id': '140', 'type': 'if_statement', 'children': ['141', '144', '166']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': '=='},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '143', 'type': 'string', 'children': [], 'value': '"GET"'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'http_session'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154', '155', '158']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'fq_url'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'verify'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'API'},{'id': '163', 'type': 'identifier', 'children': [], 'value': '_ResourcePath'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'string', 'children': [], 'value': "'clc/cacert.pem'"},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'http_session'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177', '178', '181']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'fq_url'},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'verify'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'API'},{'id': '186', 'type': 'identifier', 'children': [], 'value': '_ResourcePath'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'string', 'children': [], 'value': "'clc/cacert.pem'"},{'id': '189', 'type': 'if_statement', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'API'},{'id': '196', 'type': 'identifier', 'children': [], 'value': '_DebugRequest'},{'id': '197', 'type': 'argument_list', 'children': ['198', '219']},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '200', 'type': 'call', 'children': ['201', '218']},{'id': '201', 'type': 'attribute', 'children': ['202', '217']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'Request'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208', '209', '212']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'fq_url'},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'http_session'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'prepare'},{'id': '218', 'type': 'argument_list', 'children': []},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '222', 'type': 'if_statement', 'children': ['223', '234', '249']},{'id': '223', 'type': 'boolean_operator', 'children': ['224', '229'], 'value': 'and'},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '228'], 'value': '>='},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '228', 'type': 'integer', 'children': [], 'value': '200'},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '233'], 'value': '<'},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '233', 'type': 'integer', 'children': [], 'value': '300'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'try_statement', 'children': ['236', '244']},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': '()', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '243', 'type': 'argument_list', 'children': []},{'id': '244', 'type': 'except_clause', 'children': ['245']},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'return_statement', 'children': ['247']},{'id': '247', 'type': '()', 'children': ['248']},{'id': '248', 'type': 'dictionary', 'children': []},{'id': '249', 'type': 'else_clause', 'children': ['250']},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'try_statement', 'children': ['252', '305', '311']},{'id': '252', 'type': 'block', 'children': ['253', '276', '284', '294', '302']},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'APIFailedResponse'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'binary_operator', 'children': ['262', '263'], 'value': '%'},{'id': '262', 'type': 'string', 'children': [], 'value': '"Response code %s. %s %s %s"'},{'id': '263', 'type': 'tuple', 'children': ['264', '267', '274', '275']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '267', 'type': 'subscript', 'children': ['268', '273']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '272', 'type': 'argument_list', 'children': []},{'id': '273', 'type': 'string', 'children': [], 'value': "'message'"},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'fq_url'},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'response_status_code'},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'response_json'},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '293', 'type': 'argument_list', 'children': []},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'response_text'},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '302', 'type': 'raise_statement', 'children': ['303']},{'id': '303', 'type': '()', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '305', 'type': 'except_clause', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'APIFailedResponse'},{'id': '309', 'type': 'block', 'children': ['310']},{'id': '310', 'type': 'raise_statement', 'children': []},{'id': '311', 'type': 'except_clause', 'children': ['312']},{'id': '312', 'type': 'block', 'children': ['313', '332', '340', '346', '354']},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'assignment', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '316', 'type': 'call', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'APIFailedResponse'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'binary_operator', 'children': ['322', '323'], 'value': '%'},{'id': '322', 'type': 'string', 'children': [], 'value': '"Response code %s. %s. %s %s"'},{'id': '323', 'type': 'tuple', 'children': ['324', '327', '330', '331']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'fq_url'},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'assignment', 'children': ['334', '337']},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'response_status_code'},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'response_json'},{'id': '345', 'type': 'dictionary', 'children': []},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'assignment', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'response_text'},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '354', 'type': 'raise_statement', 'children': ['355']},{'id': '355', 'type': '()', 'children': ['356']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'e'}
def Call(method,url,payload=None,session=None,debug=False): if session is not None: token = session['token'] http_session = session['http_session'] else: if not clc._LOGIN_TOKEN_V2: API._Login() token = clc._LOGIN_TOKEN_V2 http_session = clc._REQUESTS_SESSION if payload is None: payload = {} if url[0]=='/': fq_url = "%s%s" % (clc.defaults.ENDPOINT_URL_V2,url) else: fq_url = "%s/v2/%s" % (clc.defaults.ENDPOINT_URL_V2,url) http_session.headers.update({'Authorization': "Bearer %s" % token}) if isinstance(payload, basestring): http_session.headers['content-type'] = "Application/json" else: http_session.headers['content-type'] = "application/x-www-form-urlencoded" if method=="GET": r = http_session.request(method,fq_url, params=payload, verify=API._ResourcePath('clc/cacert.pem')) else: r = http_session.request(method,fq_url, data=payload, verify=API._ResourcePath('clc/cacert.pem')) if debug: API._DebugRequest(request=requests.Request(method,fq_url,data=payload,headers=http_session.headers).prepare(), response=r) if r.status_code>=200 and r.status_code<300: try: return(r.json()) except: return({}) else: try: e = clc.APIFailedResponse("Response code %s. %s %s %s" % (r.status_code,r.json()['message'],method,fq_url)) e.response_status_code = r.status_code e.response_json = r.json() e.response_text = r.text raise(e) except clc.APIFailedResponse: raise except: e = clc.APIFailedResponse("Response code %s. %s. %s %s" % (r.status_code,r.text,method,fq_url)) e.response_status_code = r.status_code e.response_json = {} e.response_text = r.text raise(e)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'processFiles'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '5', 'type': 'block', 'children': ['6', '10', '346']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'to_process'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '15']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '12', 'type': 'subscript', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '14', 'type': 'string', 'children': [], 'value': "'filenames'"},{'id': '15', 'type': 'block', 'children': ['16', '22', '56', '65', '90', '109', '128', '141', '147', '203', '222', '228', '333', '339']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'if_statement', 'children': ['23', '26', '48']},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '25', 'type': 'string', 'children': [], 'value': "'include'"},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '32']},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '31', 'type': 'string', 'children': [], 'value': "'include'"},{'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '+'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'INCLUDE_STRING'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "''"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'list_comprehension', 'children': ['40', '43']},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'},{'id': '41', 'type': 'string', 'children': [], 'value': "'-I'"},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '47', 'type': 'string', 'children': [], 'value': "'include'"},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '55']},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '54', 'type': 'string', 'children': [], 'value': "'include'"},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'INCLUDE_STRING'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '61']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '60', 'type': 'string', 'children': [], 'value': "'file_path'"},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'getPath'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '70', '71']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '69', 'type': 'string', 'children': [], 'value': "'file_base_name'"},{'id': '70', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '71', 'type': 'subscript', 'children': ['72', '89']},{'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': 'os'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '85']},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '88', 'type': 'string', 'children': [], 'value': "'file_path'"},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '99']},{'id': '92', 'type': 'pattern_list', 'children': ['93', '96']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '95', 'type': 'string', 'children': [], 'value': "'no_extension'"},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '98', 'type': 'string', 'children': [], 'value': "'extension'"},{'id': '99', 'type': 'call', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '108', 'type': 'string', 'children': [], 'value': "'file_path'"},{'id': '109', 'type': 'if_statement', 'children': ['110', '115']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '114'], 'value': 'not'},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '113', 'type': 'string', 'children': [], 'value': "'extension'"},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'CYTHONIZABLE_FILE_EXTS'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'raise_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'CytherError'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': '"The file \'{}\' is not a designated cython file"'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '127', 'type': 'string', 'children': [], 'value': "'file_path'"},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'base_path'},{'id': '131', 'type': 'call', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '140', 'type': 'string', 'children': [], 'value': "'file_path'"},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'local_build'},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '146', 'type': 'string', 'children': [], 'value': "'local'"},{'id': '147', 'type': 'if_statement', 'children': ['148', '150', '191']},{'id': '148', 'type': 'not_operator', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'local_build'},{'id': '150', 'type': 'block', 'children': ['151', '163', '173']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'cache_name'},{'id': '154', 'type': 'call', 'children': ['155', '160']},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'base_path'},{'id': '162', 'type': 'string', 'children': [], 'value': "'__cythercache__'"},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'cache_name'},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'exist_ok'},{'id': '172', 'type': 'True', 'children': []},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '178']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '177', 'type': 'string', 'children': [], 'value': "'c_name'"},{'id': '178', 'type': 'binary_operator', 'children': ['179', '190'], 'value': '+'},{'id': '179', 'type': 'call', 'children': ['180', '185']},{'id': '180', 'type': 'attribute', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'cache_name'},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '189', 'type': 'string', 'children': [], 'value': "'file_base_name'"},{'id': '190', 'type': 'string', 'children': [], 'value': "'.c'"},{'id': '191', 'type': 'else_clause', 'children': ['192']},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '198']},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '197', 'type': 'string', 'children': [], 'value': "'c_name'"},{'id': '198', 'type': 'binary_operator', 'children': ['199', '202'], 'value': '+'},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '201', 'type': 'string', 'children': [], 'value': "'no_extension'"},{'id': '202', 'type': 'string', 'children': [], 'value': "'.c'"},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '208']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '207', 'type': 'string', 'children': [], 'value': "'object_file_name'"},{'id': '208', 'type': 'binary_operator', 'children': ['209', '221'], 'value': '+'},{'id': '209', 'type': 'subscript', 'children': ['210', '220']},{'id': '210', 'type': 'call', 'children': ['211', '216']},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '219', 'type': 'string', 'children': [], 'value': "'c_name'"},{'id': '220', 'type': 'integer', 'children': [], 'value': '0'},{'id': '221', 'type': 'string', 'children': [], 'value': "'.o'"},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '227', 'type': 'string', 'children': [], 'value': "'output_name'"},{'id': '228', 'type': 'if_statement', 'children': ['229', '232', '243', '321']},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '231', 'type': 'string', 'children': [], 'value': "'watch'"},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '238']},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '237', 'type': 'string', 'children': [], 'value': "'output_name'"},{'id': '238', 'type': 'binary_operator', 'children': ['239', '242'], 'value': '+'},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '241', 'type': 'string', 'children': [], 'value': "'no_extension'"},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_OUTPUT_EXTENSION'},{'id': '243', 'type': 'elif_clause', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'if_statement', 'children': ['247', '264', '271']},{'id': '247', 'type': 'boolean_operator', 'children': ['248', '256'], 'value': 'and'},{'id': '248', 'type': 'call', 'children': ['249', '254']},{'id': '249', 'type': 'attribute', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '256', 'type': 'call', 'children': ['257', '262']},{'id': '257', 'type': 'attribute', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '264', 'type': 'block', 'children': ['265']},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'assignment', 'children': ['267', '270']},{'id': '267', 'type': 'subscript', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '269', 'type': 'string', 'children': [], 'value': "'output_name'"},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '271', 'type': 'else_clause', 'children': ['272']},{'id': '272', 'type': 'block', 'children': ['273', '284', '296']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '276', 'type': 'call', 'children': ['277', '282']},{'id': '277', 'type': 'attribute', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '284', 'type': 'if_statement', 'children': ['285', '287']},{'id': '285', 'type': 'not_operator', 'children': ['286']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '295', 'type': 'argument_list', 'children': []},{'id': '296', 'type': 'if_statement', 'children': ['297', '305', '312']},{'id': '297', 'type': 'call', 'children': ['298', '303']},{'id': '298', 'type': 'attribute', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '305', 'type': 'block', 'children': ['306']},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '311']},{'id': '308', 'type': 'subscript', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '310', 'type': 'string', 'children': [], 'value': "'output_name'"},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'output_name'},{'id': '312', 'type': 'else_clause', 'children': ['313']},{'id': '313', 'type': 'block', 'children': ['314']},{'id': '314', 'type': 'raise_statement', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'CytherError'},{'id': '317', 'type': 'argument_list', 'children': ['318']},{'id': '318', 'type': 'concatenated_string', 'children': ['319', '320']},{'id': '319', 'type': 'string', 'children': [], 'value': "'The directory specified to write'"},{'id': '320', 'type': 'string', 'children': [], 'value': "'the output file in does not exist'"},{'id': '321', 'type': 'else_clause', 'children': ['322']},{'id': '322', 'type': 'block', 'children': ['323']},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'assignment', 'children': ['325', '328']},{'id': '325', 'type': 'subscript', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '327', 'type': 'string', 'children': [], 'value': "'output_name'"},{'id': '328', 'type': 'binary_operator', 'children': ['329', '332'], 'value': '+'},{'id': '329', 'type': 'subscript', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '331', 'type': 'string', 'children': [], 'value': "'no_extension'"},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_OUTPUT_EXTENSION'},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'assignment', 'children': ['335', '338']},{'id': '335', 'type': 'subscript', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '337', 'type': 'string', 'children': [], 'value': "'stamp_if_error'"},{'id': '338', 'type': 'integer', 'children': [], 'value': '0'},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'call', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'to_process'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '346', 'type': 'return_statement', 'children': ['347']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'to_process'}
def processFiles(args): to_process = [] for filename in args['filenames']: file = dict() if args['include']: file['include'] = INCLUDE_STRING + ''.join( ['-I' + item for item in args['include']]) else: file['include'] = INCLUDE_STRING file['file_path'] = getPath(filename) file['file_base_name'] = \ os.path.splitext(os.path.basename(file['file_path']))[0] file['no_extension'], file['extension'] = os.path.splitext( file['file_path']) if file['extension'] not in CYTHONIZABLE_FILE_EXTS: raise CytherError( "The file '{}' is not a designated cython file".format( file['file_path'])) base_path = os.path.dirname(file['file_path']) local_build = args['local'] if not local_build: cache_name = os.path.join(base_path, '__cythercache__') os.makedirs(cache_name, exist_ok=True) file['c_name'] = os.path.join(cache_name, file['file_base_name']) + '.c' else: file['c_name'] = file['no_extension'] + '.c' file['object_file_name'] = os.path.splitext(file['c_name'])[0] + '.o' output_name = args['output_name'] if args['watch']: file['output_name'] = file['no_extension']+DEFAULT_OUTPUT_EXTENSION elif output_name: if os.path.exists(output_name) and os.path.isfile(output_name): file['output_name'] = output_name else: dirname = os.path.dirname(output_name) if not dirname: dirname = os.getcwd() if os.path.exists(dirname): file['output_name'] = output_name else: raise CytherError('The directory specified to write' 'the output file in does not exist') else: file['output_name'] = file['no_extension']+DEFAULT_OUTPUT_EXTENSION file['stamp_if_error'] = 0 to_process.append(file) return to_process
{'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', '19', '32', '46', '68', '95', '123', '145', '168', '176', '217', '233', '257', '270', '281', '303']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'assignment', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'argparse'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ArgumentParser'},{'id': '12', 'type': 'argument_list', 'children': ['13', '16']},{'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '15', 'type': 'string', 'children': [], 'value': "'DistanceClassifier for classification based on distance measure in feature space.'"},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'add_help'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26', '29']},{'id': '25', 'type': 'string', 'children': [], 'value': "'INPUT_FILE'"},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '31', 'type': 'string', 'children': [], 'value': '\'Data file to perform DistanceClassifier on; ensure that the class label column is labeled as "class".\''},{'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': 'parser'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40', '43']},{'id': '38', 'type': 'string', 'children': [], 'value': "'-h'"},{'id': '39', 'type': 'string', 'children': [], 'value': "'--help'"},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '42', 'type': 'string', 'children': [], 'value': "'help'"},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '45', 'type': 'string', 'children': [], 'value': "'Show this help message and exit.'"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53', '56', '59', '62', '65']},{'id': '52', 'type': 'string', 'children': [], 'value': "'-is'"},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '55', 'type': 'string', 'children': [], 'value': "'store'"},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '58', 'type': 'string', 'children': [], 'value': "'INPUT_SEPARATOR'"},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '61', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '67', 'type': 'string', 'children': [], 'value': "'Character used to separate columns in the input file.'"},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '78', '81', '84', '89', '92']},{'id': '74', 'type': 'string', 'children': [], 'value': "'-d'"},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '77', 'type': 'string', 'children': [], 'value': "'store'"},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '80', 'type': 'string', 'children': [], 'value': "'D'"},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '83', 'type': 'string', 'children': [], 'value': "'mahalanobis'"},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '86', 'type': 'list', 'children': ['87', '88'], 'value': "['mahalanobis','euclidean']"},{'id': '87', 'type': 'string', 'children': [], 'value': "'mahalanobis'"},{'id': '88', 'type': 'string', 'children': [], 'value': "'euclidean'"},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '94', 'type': 'string', 'children': [], 'value': "'Distance metric to use.'"},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102', '105', '108', '111', '117', '120']},{'id': '101', 'type': 'string', 'children': [], 'value': "'-v'"},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '104', 'type': 'string', 'children': [], 'value': "'store'"},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '107', 'type': 'string', 'children': [], 'value': "'VERBOSITY'"},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '113', 'type': 'list', 'children': ['114', '115', '116'], 'value': '[0, 1, 2]'},{'id': '114', 'type': 'integer', 'children': [], 'value': '0'},{'id': '115', 'type': 'integer', 'children': [], 'value': '1'},{'id': '116', 'type': 'integer', 'children': [], 'value': '2'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '122', 'type': 'string', 'children': [], 'value': "'How much information DistanceClassifier communicates while it is running: 0 = none, 1 = minimal, 2 = all.'"},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130', '133', '136', '139', '142']},{'id': '129', 'type': 'string', 'children': [], 'value': "'-s'"},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '132', 'type': 'string', 'children': [], 'value': "'store'"},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '135', 'type': 'string', 'children': [], 'value': "'RANDOM_STATE'"},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '138', 'type': 'integer', 'children': [], 'value': '0'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '144', 'type': 'string', 'children': [], 'value': "'Random state for train/test split.'"},{'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': 'parser'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152', '155', '165']},{'id': '151', 'type': 'string', 'children': [], 'value': "'--version'"},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '154', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': "'DistanceClassifier {version}'"},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '164', 'type': 'identifier', 'children': [], 'value': '__version__'},{'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '167', 'type': 'string', 'children': [], 'value': "'Show DistanceClassifier\\'s version number and exit.'"},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '175', 'type': 'argument_list', 'children': []},{'id': '176', 'type': 'if_statement', 'children': ['177', '182']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '181'], 'value': '>='},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'VERBOSITY'},{'id': '181', 'type': 'integer', 'children': [], 'value': '2'},{'id': '182', 'type': 'block', 'children': ['183', '188', '212']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'string', 'children': [], 'value': "'\\nDistanceClassifier settings:'"},{'id': '188', 'type': 'for_statement', 'children': ['189', '190', '196']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '195', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'string', 'children': [], 'value': "'{}\\t=\\t{}'"},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '207', 'type': 'subscript', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '210', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'string', 'children': [], 'value': "''"},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'read_csv'},{'id': '224', 'type': 'argument_list', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'INPUT_FILE'},{'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'INPUT_SEPARATOR'},{'id': '233', 'type': 'if_statement', 'children': ['234', '241']},{'id': '234', 'type': 'comparison_operator', 'children': ['235', '236'], 'value': 'in'},{'id': '235', 'type': 'string', 'children': [], 'value': "'Class'"},{'id': '236', 'type': 'attribute', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'rename'},{'id': '247', 'type': 'argument_list', 'children': ['248', '254']},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '250', 'type': 'dictionary', 'children': ['251']},{'id': '251', 'type': 'pair', 'children': ['252', '253']},{'id': '252', 'type': 'string', 'children': [], 'value': "'Label'"},{'id': '253', 'type': 'string', 'children': [], 'value': "'label'"},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '256', 'type': 'True', 'children': []},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'RANDOM_STATE'},{'id': '260', 'type': 'conditional_expression', 'children': ['261', '264', '269'], 'value': 'if'},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'RANDOM_STATE'},{'id': '264', 'type': 'comparison_operator', 'children': ['265', '268'], 'value': '>'},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'RANDOM_STATE'},{'id': '268', 'type': 'integer', 'children': [], 'value': '0'},{'id': '269', 'type': 'None', 'children': []},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'DistanceClassifier'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'fit'},{'id': '286', 'type': 'argument_list', 'children': ['287', '298']},{'id': '287', 'type': 'attribute', 'children': ['288', '297']},{'id': '288', 'type': 'call', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294']},{'id': '293', 'type': 'string', 'children': [], 'value': "'label'"},{'id': '294', 'type': 'keyword_argument', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '296', 'type': 'integer', 'children': [], 'value': '1'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '298', 'type': 'attribute', 'children': ['299', '302']},{'id': '299', 'type': 'subscript', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '301', 'type': 'string', 'children': [], 'value': "'label'"},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '311', 'type': 'argument_list', 'children': ['312', '323']},{'id': '312', 'type': 'attribute', 'children': ['313', '322']},{'id': '313', 'type': 'call', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '317', 'type': 'argument_list', 'children': ['318', '319']},{'id': '318', 'type': 'string', 'children': [], 'value': "'label'"},{'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '321', 'type': 'integer', 'children': [], 'value': '1'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '323', 'type': 'attribute', 'children': ['324', '327']},{'id': '324', 'type': 'subscript', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '326', 'type': 'string', 'children': [], 'value': "'label'"},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'values'}
def main(): parser = argparse.ArgumentParser(description='DistanceClassifier for classification based on distance measure in feature space.', add_help=False) parser.add_argument('INPUT_FILE', type=str, help='Data file to perform DistanceClassifier on; ensure that the class label column is labeled as "class".') parser.add_argument('-h', '--help', action='help', help='Show this help message and exit.') parser.add_argument('-is', action='store', dest='INPUT_SEPARATOR', default='\t', type=str, help='Character used to separate columns in the input file.') parser.add_argument('-d', action='store', dest='D', default='mahalanobis',choices = ['mahalanobis','euclidean'], type=str, help='Distance metric to use.') parser.add_argument('-v', action='store', dest='VERBOSITY', default=1, choices=[0, 1, 2], type=int, help='How much information DistanceClassifier communicates while it is running: 0 = none, 1 = minimal, 2 = all.') parser.add_argument('-s', action='store', dest='RANDOM_STATE', default=0, type=int, help='Random state for train/test split.') parser.add_argument('--version', action='version', version='DistanceClassifier {version}'.format(version=__version__), help='Show DistanceClassifier\'s version number and exit.') args = parser.parse_args() if args.VERBOSITY >= 2: print('\nDistanceClassifier settings:') for arg in sorted(args.__dict__): print('{}\t=\t{}'.format(arg, args.__dict__[arg])) print('') input_data = pd.read_csv(args.INPUT_FILE, sep=args.INPUT_SEPARATOR) if 'Class' in input_data.columns.values: input_data.rename(columns={'Label': 'label'}, inplace=True) RANDOM_STATE = args.RANDOM_STATE if args.RANDOM_STATE > 0 else None dc = DistanceClassifier(d = args.D) dc.fit(input_data.drop('label',axis=1).values, input_data['label'].values) print(dc.score(input_data.drop('label',axis=1).values, input_data['label'].values))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'delete'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': '_lock'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '20', '44', '312', '320']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'link_path'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_link_path'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '20', 'type': 'if_statement', 'children': ['21', '22', '36']},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_lock'},{'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': 'file_lock'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_exclusive_lock'},{'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': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_lock_path'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'links'"},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '36', 'type': 'else_clause', 'children': ['37']},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'file_lock'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_no_lock'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'with_statement', 'children': ['45', '48']},{'id': '45', 'type': 'with_clause', 'children': ['46']},{'id': '46', 'type': 'with_item', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'file_lock'},{'id': '48', 'type': 'block', 'children': ['49', '57', '66', '89', '98', '304']},{'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': 'logger'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'Acquired or inherited lock for link %s.'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '57', 'type': 'if_statement', 'children': ['58', '63']},{'id': '58', 'type': 'not_operator', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_path_exists'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'link_path'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'raise_statement', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'FiletrackerFileNotFoundError'},{'id': '66', 'type': 'if_statement', 'children': ['67', '73']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '72'], 'value': '>'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_file_version'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'link_path'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '73', 'type': 'block', 'children': ['74', '87']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81', '82', '83']},{'id': '80', 'type': 'string', 'children': [], 'value': "'Tried to delete newer version of %s (%d < %d), ignoring.'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_file_version'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'link_path'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'False', 'children': []},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_digest_for_link'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '98', 'type': 'with_statement', 'children': ['99', '111']},{'id': '99', 'type': 'with_clause', 'children': ['100']},{'id': '100', 'type': 'with_item', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': '_exclusive_lock'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': '_lock_path'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': "'blobs'"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '111', 'type': 'block', 'children': ['112', '120', '124', '267', '274', '281', '289']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119']},{'id': '118', 'type': 'string', 'children': [], 'value': "'Acquired lock for blob %s.'"},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'should_delete_blob'},{'id': '123', 'type': 'False', 'children': []},{'id': '124', 'type': 'with_statement', 'children': ['125', '135']},{'id': '125', 'type': 'with_clause', 'children': ['126']},{'id': '126', 'type': 'with_item', 'children': ['127']},{'id': '127', 'type': 'as_pattern', 'children': ['128', '133']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_db_transaction'},{'id': '132', 'type': 'argument_list', 'children': []},{'id': '133', 'type': 'as_pattern_target', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'txn'},{'id': '135', 'type': 'block', 'children': ['136', '143', '151', '165', '175', '182', '260']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'string', 'children': [], 'value': "'Started DB transaction (deleting link).'"},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'digest_bytes'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '150', 'type': 'argument_list', 'children': []},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'link_count'},{'id': '154', 'type': 'call', 'children': ['155', '160']},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'digest_bytes'},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'txn'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'txn'},{'id': '165', 'type': 'if_statement', 'children': ['166', '169']},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': 'is'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'link_count'},{'id': '168', 'type': 'None', 'children': []},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'raise_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'string', 'children': [], 'value': '"File exists but has no key in db"'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'link_count'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'link_count'},{'id': '182', 'type': 'if_statement', 'children': ['183', '186', '232']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': '=='},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'link_count'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'block', 'children': ['187', '195', '207', '228']},{'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': 'logger'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '192', 'type': 'argument_list', 'children': ['193', '194']},{'id': '193', 'type': 'string', 'children': [], 'value': "'Deleting last link to blob %s.'"},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '202']},{'id': '197', 'type': 'attribute', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'digest_bytes'},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'txn'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'txn'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '214']},{'id': '209', 'type': 'attribute', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '214', 'type': 'argument_list', 'children': ['215', '225']},{'id': '215', 'type': 'call', 'children': ['216', '224']},{'id': '216', 'type': 'attribute', 'children': ['217', '223']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'string', 'children': [], 'value': "'{}:logical_size'"},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '224', 'type': 'argument_list', 'children': []},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'txn'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'txn'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'should_delete_blob'},{'id': '231', 'type': 'True', 'children': []},{'id': '232', 'type': 'else_clause', 'children': ['233']},{'id': '233', 'type': 'block', 'children': ['234', '247']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'new_count'},{'id': '237', 'type': 'call', 'children': ['238', '246']},{'id': '238', 'type': 'attribute', 'children': ['239', '245']},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'binary_operator', 'children': ['243', '244'], 'value': '-'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'link_count'},{'id': '244', 'type': 'integer', 'children': [], 'value': '1'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '246', 'type': 'argument_list', 'children': []},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'call', 'children': ['249', '254']},{'id': '249', 'type': 'attribute', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'put'},{'id': '254', 'type': 'argument_list', 'children': ['255', '256', '257']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'digest_bytes'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'new_count'},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'txn'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'txn'},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'string', 'children': [], 'value': "'Committing DB transaction (deleting link).'"},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'string', 'children': [], 'value': "'Committed DB transaction (deleting link).'"},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'unlink'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'link_path'},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '286', 'type': 'argument_list', 'children': ['287', '288']},{'id': '287', 'type': 'string', 'children': [], 'value': "'Deleted link %s.'"},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '289', 'type': 'if_statement', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'should_delete_blob'},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'unlink'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '301', 'type': 'identifier', 'children': [], 'value': '_blob_path'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'digest'},{'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': 'logger'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311']},{'id': '310', 'type': 'string', 'children': [], 'value': "'Released lock for blob %s.'"},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'digest'},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '317', 'type': 'argument_list', 'children': ['318', '319']},{'id': '318', 'type': 'string', 'children': [], 'value': "'Released (or gave back) lock for link %s.'"},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '320', 'type': 'return_statement', 'children': ['321']},{'id': '321', 'type': 'True', 'children': []}
def delete(self, name, version, _lock=True): link_path = self._link_path(name) if _lock: file_lock = _exclusive_lock(self._lock_path('links', name)) else: file_lock = _no_lock() with file_lock: logger.debug('Acquired or inherited lock for link %s.', name) if not _path_exists(link_path): raise FiletrackerFileNotFoundError if _file_version(link_path) > version: logger.info( 'Tried to delete newer version of %s (%d < %d), ignoring.', name, version, _file_version(link_path)) return False digest = self._digest_for_link(name) with _exclusive_lock(self._lock_path('blobs', digest)): logger.debug('Acquired lock for blob %s.', digest) should_delete_blob = False with self._db_transaction() as txn: logger.debug('Started DB transaction (deleting link).') digest_bytes = digest.encode() link_count = self.db.get(digest_bytes, txn=txn) if link_count is None: raise RuntimeError("File exists but has no key in db") link_count = int(link_count) if link_count == 1: logger.debug('Deleting last link to blob %s.', digest) self.db.delete(digest_bytes, txn=txn) self.db.delete( '{}:logical_size'.format(digest).encode(), txn=txn) should_delete_blob = True else: new_count = str(link_count - 1).encode() self.db.put(digest_bytes, new_count, txn=txn) logger.debug('Committing DB transaction (deleting link).') logger.debug('Committed DB transaction (deleting link).') os.unlink(link_path) logger.debug('Deleted link %s.', name) if should_delete_blob: os.unlink(self._blob_path(digest)) logger.debug('Released lock for blob %s.', digest) logger.debug('Released (or gave back) lock for link %s.', name) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'wait_socks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sock_events'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'inmask'},{'id': '7', 'type': 'integer', 'children': [], 'value': '1'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'outmask'},{'id': '10', 'type': 'integer', 'children': [], 'value': '2'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '19', '58', '63', '67', '71', '135']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'for_statement', 'children': ['20', '23', '24']},{'id': '20', 'type': 'pattern_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sock_events'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '35']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'zmq'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'backend'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'Socket'},{'id': '35', 'type': 'block', 'children': ['36', '46']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_check_events'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43', '44', '45']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'inmask'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'outmask'},{'id': '46', 'type': 'if_statement', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '48', 'type': 'block', 'children': ['49']},{'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': 'results'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'tuple', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '58', 'type': 'if_statement', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'fd_map'},{'id': '66', 'type': 'dictionary', 'children': []},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'fd_events'},{'id': '70', 'type': 'list', 'children': [], 'value': '[]'},{'id': '71', 'type': 'for_statement', 'children': ['72', '75', '76']},{'id': '72', 'type': 'pattern_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sock_events'},{'id': '76', 'type': 'block', 'children': ['77', '120', '126']},{'id': '77', 'type': 'if_statement', 'children': ['78', '87', '99', '110']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '82', 'type': 'attribute', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'zmq'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'backend'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'Socket'},{'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': 'fd'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'getsockopt'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'zmq'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'FD'},{'id': '99', 'type': 'elif_clause', 'children': ['100', '105']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '110', 'type': 'else_clause', 'children': ['111']},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'fileno'},{'id': '119', 'type': 'argument_list', 'children': []},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '125']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'fd_map'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sock'},{'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': 'fd_events'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'tuple', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '135', 'type': 'while_statement', 'children': ['136', '137']},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'block', 'children': ['138', '146', '158', '164', '168', '215', '220']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'started'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'descriptor'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'wait_fds'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155', '156', '157']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'fd_events'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'inmask'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'outmask'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '158', 'type': 'if_statement', 'children': ['159', '161']},{'id': '159', 'type': 'not_operator', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'return_statement', 'children': ['163']},{'id': '163', 'type': 'list', 'children': [], 'value': '[]'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '167', 'type': 'list', 'children': [], 'value': '[]'},{'id': '168', 'type': 'for_statement', 'children': ['169', '172', '173']},{'id': '169', 'type': 'pattern_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '173', 'type': 'block', 'children': ['174', '180', '206']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'fd_map'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '180', 'type': 'if_statement', 'children': ['181', '190']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '185', 'type': 'attribute', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'zmq'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'backend'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'Socket'},{'id': '190', 'type': 'block', 'children': ['191', '201']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': '_check_events'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198', '199', '200']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'inmask'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'outmask'},{'id': '201', 'type': 'if_statement', 'children': ['202', '204']},{'id': '202', 'type': 'not_operator', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'continue_statement', 'children': []},{'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': 'results'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'tuple', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '215', 'type': 'if_statement', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'return_statement', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'augmented_assignment', 'children': ['222', '223'], 'value': '-='},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '223', 'type': 'binary_operator', 'children': ['224', '229'], 'value': '-'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '228', 'type': 'argument_list', 'children': []},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'started'}
def wait_socks(sock_events, inmask=1, outmask=2, timeout=None): results = [] for sock, mask in sock_events: if isinstance(sock, zmq.backend.Socket): mask = _check_events(sock, mask, inmask, outmask) if mask: results.append((sock, mask)) if results: return results fd_map = {} fd_events = [] for sock, mask in sock_events: if isinstance(sock, zmq.backend.Socket): fd = sock.getsockopt(zmq.FD) elif isinstance(sock, int): fd = sock else: fd = sock.fileno() fd_map[fd] = sock fd_events.append((fd, mask)) while 1: started = time.time() active = descriptor.wait_fds(fd_events, inmask, outmask, timeout) if not active: return [] results = [] for fd, mask in active: sock = fd_map[fd] if isinstance(sock, zmq.backend.Socket): mask = _check_events(sock, mask, inmask, outmask) if not mask: continue results.append((sock, mask)) if results: return results timeout -= time.time() - started
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sync_ldap_user_membership'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ldap_groups'},{'id': '7', 'type': 'block', 'children': ['8', '12', '26', '33', '37', '41', '45', '51', '55', '244', '280', '312', '318', '324', '330']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'groupname_field'},{'id': '11', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'actualGroups'},{'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': 'user'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'values_list'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'flat'},{'id': '25', 'type': 'True', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'user_Membership_total'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ldap_groups'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'user_Membership_added'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'user_Membership_deleted'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'user_Membership_errors'},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'augmented_assignment', 'children': ['47', '48'], 'value': '+='},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ldap_groups'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'conf_LDAP_SYNC_GROUP_MEMBERSHIP_ADD_DEFAULT'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ldap_name_groups'},{'id': '54', 'type': 'list', 'children': [], 'value': '[]'},{'id': '55', 'type': 'for_statement', 'children': ['56', '59', '60']},{'id': '56', 'type': 'pattern_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'cname'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ldap_attributes'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ldap_groups'},{'id': '60', 'type': 'block', 'children': ['61', '65', '98', '130']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '64', 'type': 'dictionary', 'children': []},{'id': '65', 'type': 'try_statement', 'children': ['66', '94']},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'for_statement', 'children': ['68', '71', '76']},{'id': '68', 'type': 'pattern_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'attribute'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ldap_attributes'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '86']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '81', 'type': 'subscript', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'conf_LDAP_SYNC_GROUP_ATTRIBUTES'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'attribute'},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '94', 'type': 'except_clause', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'continue_statement', 'children': []},{'id': '98', 'type': 'try_statement', 'children': ['99', '113']},{'id': '99', 'type': 'block', 'children': ['100', '106']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'groupname_field'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ldap_name_groups'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '113', 'type': 'except_clause', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '115', 'type': 'block', 'children': ['116', '125', '129']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '%'},{'id': '123', 'type': 'string', 'children': [], 'value': '"Group is missing a required attribute \'%s\'"'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'groupname_field'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'augmented_assignment', 'children': ['127', '128'], 'value': '+='},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'user_Membership_errors'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'continue_statement', 'children': []},{'id': '130', 'type': 'if_statement', 'children': ['131', '135']},{'id': '131', 'type': '()', 'children': ['132']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': 'not'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'actualGroups'},{'id': '135', 'type': 'block', 'children': ['136', '148']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '139', 'type': 'dictionary', 'children': ['140', '145']},{'id': '140', 'type': 'pair', 'children': ['141', '144']},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '+'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'groupname_field'},{'id': '143', 'type': 'string', 'children': [], 'value': "'__iexact'"},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '145', 'type': 'pair', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': "'defaults'"},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '148', 'type': 'try_statement', 'children': ['149', '189', '194', '217']},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'if_statement', 'children': ['151', '155', '170']},{'id': '151', 'type': '()', 'children': ['152']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'conf_LDAP_SYNC_GROUP_MEMBERSHIP_CREATE_IF_NOT_EXISTS'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '161']},{'id': '158', 'type': 'pattern_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'created'},{'id': '161', 'type': 'call', 'children': ['162', '167']},{'id': '162', 'type': 'attribute', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'Group'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'get_or_create'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'dictionary_splat', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '170', 'type': 'else_clause', 'children': ['171']},{'id': '171', 'type': 'block', 'children': ['172', '185']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '175', 'type': 'call', 'children': ['176', '181']},{'id': '176', 'type': 'attribute', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'Group'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'created'},{'id': '188', 'type': 'False', 'children': []},{'id': '189', 'type': 'except_clause', 'children': ['190', '192']},{'id': '190', 'type': '()', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ObjectDoesNotExist'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'continue_statement', 'children': []},{'id': '194', 'type': 'except_clause', 'children': ['195', '201']},{'id': '195', 'type': 'as_pattern', 'children': ['196', '199']},{'id': '196', 'type': 'tuple', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'IntegrityError'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'DataError'},{'id': '199', 'type': 'as_pattern_target', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '201', 'type': 'block', 'children': ['202', '213']},{'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': 'logger'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '%'},{'id': '209', 'type': 'string', 'children': [], 'value': '"Error creating group %s: %s"'},{'id': '210', 'type': 'tuple', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'augmented_assignment', 'children': ['215', '216'], 'value': '+='},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'user_Membership_errors'},{'id': '216', 'type': 'integer', 'children': [], 'value': '1'},{'id': '217', 'type': 'else_clause', 'children': ['218']},{'id': '218', 'type': 'block', 'children': ['219', '231', '240']},{'id': '219', 'type': 'if_statement', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'created'},{'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': 'logger'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'binary_operator', 'children': ['229', '230'], 'value': '%'},{'id': '229', 'type': 'string', 'children': [], 'value': '"Created group %s"'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '238']},{'id': '233', 'type': 'attribute', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'user_set'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'augmented_assignment', 'children': ['242', '243'], 'value': '+='},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'user_Membership_added'},{'id': '243', 'type': 'integer', 'children': [], 'value': '1'},{'id': '244', 'type': 'for_statement', 'children': ['245', '246', '247']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'check_group'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'actualGroups'},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'if_statement', 'children': ['249', '253']},{'id': '249', 'type': '()', 'children': ['250']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': 'not'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'check_group'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'ldap_name_groups'},{'id': '253', 'type': 'block', 'children': ['254', '267', '276']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '257', 'type': 'call', 'children': ['258', '263']},{'id': '258', 'type': 'attribute', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'Group'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'check_group'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '274']},{'id': '269', 'type': 'attribute', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'user_set'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'augmented_assignment', 'children': ['278', '279'], 'value': '+='},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'user_Membership_deleted'},{'id': '279', 'type': 'integer', 'children': [], 'value': '1'},{'id': '280', 'type': 'if_statement', 'children': ['281', '291']},{'id': '281', 'type': '()', 'children': ['282']},{'id': '282', 'type': 'boolean_operator', 'children': ['283', '287'], 'value': 'or'},{'id': '283', 'type': '()', 'children': ['284']},{'id': '284', 'type': 'comparison_operator', 'children': ['285', '286'], 'value': '>'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'user_Membership_deleted'},{'id': '286', 'type': 'integer', 'children': [], 'value': '0'},{'id': '287', 'type': '()', 'children': ['288']},{'id': '288', 'type': 'comparison_operator', 'children': ['289', '290'], 'value': '>'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'user_Membership_added'},{'id': '290', 'type': 'integer', 'children': [], 'value': '0'},{'id': '291', 'type': 'block', 'children': ['292', '298']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '297', 'type': 'argument_list', 'children': []},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'binary_operator', 'children': ['305', '306'], 'value': '%'},{'id': '305', 'type': 'string', 'children': [], 'value': '"Group membership for user %s synchronized: %d Added, %d Removed"'},{'id': '306', 'type': 'tuple', 'children': ['307', '310', '311']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'user_Membership_added'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'user_Membership_deleted'},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'augmented_assignment', 'children': ['314', '317'], 'value': '+='},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'stats_membership_total'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'user_Membership_total'},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'augmented_assignment', 'children': ['320', '323'], 'value': '+='},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'stats_membership_added'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'user_Membership_added'},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'augmented_assignment', 'children': ['326', '329'], 'value': '+='},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'stats_membership_deleted'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'user_Membership_deleted'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'augmented_assignment', 'children': ['332', '335'], 'value': '+='},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'stats_membership_errors'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'user_Membership_errors'}
def sync_ldap_user_membership(self, user, ldap_groups): groupname_field = 'name' actualGroups = user.groups.values_list('name', flat=True) user_Membership_total = len(ldap_groups) user_Membership_added = 0 user_Membership_deleted = 0 user_Membership_errors = 0 ldap_groups += self.conf_LDAP_SYNC_GROUP_MEMBERSHIP_ADD_DEFAULT ldap_name_groups = [] for cname, ldap_attributes in ldap_groups: defaults = {} try: for name, attribute in ldap_attributes.items(): defaults[self.conf_LDAP_SYNC_GROUP_ATTRIBUTES[name]] = attribute[0].decode('utf-8') except AttributeError: continue try: groupname = defaults[groupname_field] ldap_name_groups.append(groupname) except KeyError: logger.warning("Group is missing a required attribute '%s'" % groupname_field) user_Membership_errors += 1 continue if (groupname not in actualGroups): kwargs = { groupname_field + '__iexact': groupname, 'defaults': defaults, } try: if (self.conf_LDAP_SYNC_GROUP_MEMBERSHIP_CREATE_IF_NOT_EXISTS): group, created = Group.objects.get_or_create(**kwargs) else: group = Group.objects.get(name=groupname) created = False except (ObjectDoesNotExist): continue except (IntegrityError, DataError) as e: logger.error("Error creating group %s: %s" % (groupname, e)) user_Membership_errors += 1 else: if created: logger.debug("Created group %s" % groupname) group.user_set.add(user) user_Membership_added += 1 for check_group in actualGroups: if (check_group not in ldap_name_groups): group = Group.objects.get(name=check_group) group.user_set.remove(user) user_Membership_deleted += 1 if ((user_Membership_deleted > 0) or (user_Membership_added > 0)): group.save() logger.info("Group membership for user %s synchronized: %d Added, %d Removed" % (user.username, user_Membership_added, user_Membership_deleted)) self.stats_membership_total += user_Membership_total self.stats_membership_added += user_Membership_added self.stats_membership_deleted += user_Membership_deleted self.stats_membership_errors += user_Membership_errors
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'},{'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': 'block'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '113', '139']},{'id': '12', 'type': 'if_statement', 'children': ['13', '17']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '17', 'type': 'block', 'children': ['18', '26', '34', '49', '62', '73', '83']},{'id': '18', 'type': 'if_statement', 'children': ['19', '21']},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'raise_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Empty'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'getcurrent'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '37', 'type': 'conditional_expression', 'children': ['38', '39', '42'], 'value': 'if'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'binary_operator', 'children': ['43', '48'], 'value': '+'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '49', 'type': 'if_statement', 'children': ['50', '53']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'schedule_at'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '_waiters'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'tuple', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '82']},{'id': '75', 'type': 'attribute', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'mainloop'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'switch'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'if_statement', 'children': ['84', '87']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'is'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '86', 'type': 'None', 'children': []},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'if_statement', 'children': ['89', '97']},{'id': '89', 'type': 'not_operator', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_remove_timer'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '97', 'type': 'block', 'children': ['98', '109']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_waiters'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'tuple', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '109', 'type': 'raise_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'Empty'},{'id': '112', 'type': 'argument_list', 'children': []},{'id': '113', 'type': 'if_statement', 'children': ['114', '123']},{'id': '114', 'type': 'boolean_operator', 'children': ['115', '120'], 'value': 'and'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '119', 'type': 'argument_list', 'children': []},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_waiters'},{'id': '123', 'type': 'block', 'children': ['124']},{'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': 'scheduler'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'schedule'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'subscript', 'children': ['131', '138']},{'id': '131', 'type': 'call', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': '_waiters'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'popleft'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'integer', 'children': [], 'value': '0'},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': '_get'},{'id': '144', 'type': 'argument_list', 'children': []}
def get(self, block=True, timeout=None): if not self._data: if not block: raise Empty() current = compat.getcurrent() waketime = None if timeout is None else time.time() + timeout if timeout is not None: scheduler.schedule_at(waketime, current) self._waiters.append((current, waketime)) scheduler.state.mainloop.switch() if timeout is not None: if not scheduler._remove_timer(waketime, current): self._waiters.remove((current, waketime)) raise Empty() if self.full() and self._waiters: scheduler.schedule(self._waiters.popleft()[0]) return self._get()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'put'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '115', '142', '156', '162']},{'id': '13', 'type': 'if_statement', 'children': ['14', '19']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '28', '36', '51', '64', '75', '85']},{'id': '20', 'type': 'if_statement', 'children': ['21', '23']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'raise_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'Full'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'getcurrent'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '39', 'type': 'conditional_expression', 'children': ['40', '41', '44'], 'value': 'if'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'binary_operator', 'children': ['45', '50'], 'value': '+'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '51', 'type': 'if_statement', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'block', 'children': ['56']},{'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': 'scheduler'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'schedule_at'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '71']},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_waiters'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'tuple', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '84']},{'id': '77', 'type': 'attribute', 'children': ['78', '83']},{'id': '78', 'type': 'attribute', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'mainloop'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'switch'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'if_statement', 'children': ['86', '89']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'is'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '88', 'type': 'None', 'children': []},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'if_statement', 'children': ['91', '99']},{'id': '91', 'type': 'not_operator', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_remove_timer'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '99', 'type': 'block', 'children': ['100', '111']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_waiters'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'tuple', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '111', 'type': 'raise_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'Full'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'if_statement', 'children': ['116', '126']},{'id': '116', 'type': 'boolean_operator', 'children': ['117', '120'], 'value': 'and'},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': '_waiters'},{'id': '120', 'type': 'not_operator', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'block', 'children': ['127']},{'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': 'scheduler'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'schedule'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'subscript', 'children': ['134', '141']},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_waiters'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'popleft'},{'id': '140', 'type': 'argument_list', 'children': []},{'id': '141', 'type': 'integer', 'children': [], 'value': '0'},{'id': '142', 'type': 'if_statement', 'children': ['143', '147']},{'id': '143', 'type': 'not_operator', 'children': ['144']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': '_open_tasks'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '155']},{'id': '150', 'type': 'attribute', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_jobs_done'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '155', 'type': 'argument_list', 'children': []},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'augmented_assignment', 'children': ['158', '161'], 'value': '+='},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': '_open_tasks'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_put'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'item'}
def put(self, item, block=True, timeout=None): if self.full(): if not block: raise Full() current = compat.getcurrent() waketime = None if timeout is None else time.time() + timeout if timeout is not None: scheduler.schedule_at(waketime, current) self._waiters.append((current, waketime)) scheduler.state.mainloop.switch() if timeout is not None: if not scheduler._remove_timer(waketime, current): self._waiters.remove((current, waketime)) raise Full() if self._waiters and not self.full(): scheduler.schedule(self._waiters.popleft()[0]) if not self._open_tasks: self._jobs_done.clear() self._open_tasks += 1 self._put(item)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_compress_tokens'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '5', 'type': 'block', 'children': ['6', '10', '50', '57', '61', '155']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'recorder'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '15']},{'id': '11', 'type': 'function_name', 'children': [], 'value': '_edge_case_stray_end_quoted'},{'id': '12', 'type': 'parameters', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '21']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Token'},{'id': '23', 'type': 'argument_list', 'children': ['24', '29', '36', '43']},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'TokenType'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'UnquotedLiteral'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tokens_len'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'with_statement', 'children': ['62', '70']},{'id': '62', 'type': 'with_clause', 'children': ['63']},{'id': '63', 'type': 'with_item', 'children': ['64']},{'id': '64', 'type': 'as_pattern', 'children': ['65', '68']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_EdgeCaseStrayParens'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'as_pattern_target', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'edge_case_stray_parens'},{'id': '70', 'type': 'block', 'children': ['71', '81']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'edge_cases'},{'id': '74', 'type': 'list', 'children': ['75', '78'], 'value': '[\n (_is_paren_type, edge_case_stray_parens),\n (_is_end_quoted_type, _edge_case_stray_end_quoted),\n ]'},{'id': '75', 'type': 'tuple', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_is_paren_type'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'edge_case_stray_parens'},{'id': '78', 'type': 'tuple', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': '_is_end_quoted_type'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_edge_case_stray_end_quoted'},{'id': '81', 'type': 'while_statement', 'children': ['82', '85']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '<'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'tokens_len'},{'id': '85', 'type': 'block', 'children': ['86', '95', '151']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'recorder'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': '_find_recorder'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93', '94']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'recorder'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '95', 'type': 'if_statement', 'children': ['96', '99', '127']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'is'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'recorder'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'block', 'children': ['100', '111']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'recorder'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'consume_token'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'tokens_len'},{'id': '111', 'type': 'if_statement', 'children': ['112', '115']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'is'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '114', 'type': 'None', 'children': []},{'id': '115', 'type': 'block', 'children': ['116', '123']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '122']},{'id': '118', 'type': 'tuple_pattern', 'children': ['119', '120', '121']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'tokens_len'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'recorder'},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'else_clause', 'children': ['128']},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'for_statement', 'children': ['130', '133', '134']},{'id': '130', 'type': 'pattern_list', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'handler'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'edge_cases'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'if_statement', 'children': ['136', '144']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'attribute', 'children': ['140', '143']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'handler'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'augmented_assignment', 'children': ['153', '154'], 'value': '+='},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '154', 'type': 'integer', 'children': [], 'value': '1'},{'id': '155', 'type': 'return_statement', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'tokens'}
def _compress_tokens(tokens): recorder = None def _edge_case_stray_end_quoted(tokens, index): tokens[index] = Token(type=TokenType.UnquotedLiteral, content=tokens[index].content, line=tokens[index].line, col=tokens[index].col) tokens_len = len(tokens) index = 0 with _EdgeCaseStrayParens() as edge_case_stray_parens: edge_cases = [ (_is_paren_type, edge_case_stray_parens), (_is_end_quoted_type, _edge_case_stray_end_quoted), ] while index < tokens_len: recorder = _find_recorder(recorder, tokens, index) if recorder is not None: result = recorder.consume_token(tokens, index, tokens_len) if result is not None: (index, tokens_len, tokens) = result recorder = None else: for matcher, handler in edge_cases: if matcher(tokens[index].type): handler(tokens, index) index += 1 return tokens
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse_dependencies'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '5', 'type': 'block', 'children': ['6', '15', '24', '31', '35', '39', '70', '85']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_get_contents_between'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '13', 'type': 'string', 'children': [], 'value': "'('"},{'id': '14', 'type': 'string', 'children': [], 'value': "')'"},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'unsorted_dependencies'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "','"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_check_parameters'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'unsorted_dependencies'},{'id': '29', 'type': 'tuple', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'buildable_dependencies'},{'id': '34', 'type': 'list', 'children': [], 'value': '[]'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'given_dependencies'},{'id': '38', 'type': 'list', 'children': [], 'value': '[]'},{'id': '39', 'type': 'for_statement', 'children': ['40', '41', '42']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'dependency'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'unsorted_dependencies'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'if_statement', 'children': ['44', '49', '61']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': '=='},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'dependency'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'given_dependencies'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dependency'},{'id': '58', 'type': 'slice', 'children': ['59', '60']},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'colon', 'children': []},{'id': '61', 'type': 'else_clause', 'children': ['62']},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'buildable_dependencies'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'dependency'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '75', 'type': 'slice', 'children': ['76', '84']},{'id': '76', 'type': 'binary_operator', 'children': ['77', '83'], 'value': '+'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'string', 'children': [], 'value': "')'"},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'colon', 'children': []},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'expression_list', 'children': ['87', '88', '89']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'buildable_dependencies'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'given_dependencies'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'string'}
def _parse_dependencies(string): contents = _get_contents_between(string, '(', ')') unsorted_dependencies = contents.split(',') _check_parameters(unsorted_dependencies, ('?',)) buildable_dependencies = [] given_dependencies = [] for dependency in unsorted_dependencies: if dependency[0] == '?': given_dependencies.append(dependency[1:]) else: buildable_dependencies.append(dependency) string = string[string.index(')') + 1:] return buildable_dependencies, given_dependencies, string
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'wait_fds'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fd_events'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'inmask'},{'id': '7', 'type': 'integer', 'children': [], 'value': '1'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'outmask'},{'id': '10', 'type': 'integer', 'children': [], 'value': '2'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '23', '27', '31', '35', '81', '148', '191', '219', '234']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'getcurrent'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'activated'},{'id': '26', 'type': 'dictionary', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'poll_regs'},{'id': '30', 'type': 'dictionary', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'callback_refs'},{'id': '34', 'type': 'dictionary', 'children': []},{'id': '35', 'type': 'function_definition', 'children': ['36', '37', '40']},{'id': '36', 'type': 'function_name', 'children': [], 'value': 'activate'},{'id': '37', 'type': 'parameters', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '40', 'type': 'block', 'children': ['41', '67', '75']},{'id': '41', 'type': 'if_statement', 'children': ['42', '48']},{'id': '42', 'type': 'boolean_operator', 'children': ['43', '45'], 'value': 'and'},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'activated'},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '!='},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'block', 'children': ['49', '56']},{'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': 'scheduler'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'schedule'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '56', 'type': 'if_statement', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '58', 'type': 'block', 'children': ['59']},{'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': 'scheduler'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_remove_timer'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'activated'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '74', 'type': 'integer', 'children': [], 'value': '0'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'augmented_assignment', 'children': ['77', '80'], 'value': '|='},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'activated'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '81', 'type': 'for_statement', 'children': ['82', '85', '86']},{'id': '82', 'type': 'pattern_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'fd_events'},{'id': '86', 'type': 'block', 'children': ['87', '91', '95', '111', '127', '135']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'readable'},{'id': '90', 'type': 'None', 'children': []},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'writable'},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'if_statement', 'children': ['96', '99']},{'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '&'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'inmask'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'readable'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'activate'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'inmask'},{'id': '111', 'type': 'if_statement', 'children': ['112', '115']},{'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '&'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'outmask'},{'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': 'writable'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125', '126']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'activate'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'outmask'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'callback_refs'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '132', 'type': 'tuple', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'readable'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'writable'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'poll_regs'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '143', 'type': 'identifier', 'children': [], 'value': '_register_fd'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146', '147']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'readable'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'writable'},{'id': '148', 'type': 'if_statement', 'children': ['149', '150', '168', '179']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '150', 'type': 'block', 'children': ['151', '161']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '154', 'type': 'binary_operator', 'children': ['155', '160'], 'value': '+'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'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': 'scheduler'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'pause_until'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'waketime'},{'id': '168', 'type': 'elif_clause', 'children': ['169', '172']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': '=='},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '171', 'type': 'integer', 'children': [], 'value': '0'},{'id': '172', 'type': 'block', 'children': ['173']},{'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': 'scheduler'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'pause'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'else_clause', 'children': ['180']},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '190']},{'id': '183', 'type': 'attribute', 'children': ['184', '189']},{'id': '184', 'type': 'attribute', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'mainloop'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'switch'},{'id': '190', 'type': 'argument_list', 'children': []},{'id': '191', 'type': 'for_statement', 'children': ['192', '195', '200']},{'id': '192', 'type': 'pattern_list', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'reg'},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'poll_regs'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '199', 'type': 'argument_list', 'children': []},{'id': '200', 'type': 'block', 'children': ['201', '209']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '206']},{'id': '203', 'type': 'pattern_list', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'readable'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'writable'},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'callback_refs'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '213', 'type': 'identifier', 'children': [], 'value': '_unregister_fd'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216', '217', '218']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'readable'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'writable'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'reg'},{'id': '219', 'type': 'if_statement', 'children': ['220', '225']},{'id': '220', 'type': 'attribute', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'interrupted'},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'raise_statement', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '229', 'type': 'argument_list', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'errno'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'EINTR'},{'id': '233', 'type': 'string', 'children': [], 'value': '"interrupted system call"'},{'id': '234', 'type': 'return_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'activated'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '239', 'type': 'argument_list', 'children': []}
def wait_fds(fd_events, inmask=1, outmask=2, timeout=None): current = compat.getcurrent() activated = {} poll_regs = {} callback_refs = {} def activate(fd, event): if not activated and timeout != 0: scheduler.schedule(current) if timeout: scheduler._remove_timer(waketime, current) activated.setdefault(fd, 0) activated[fd] |= event for fd, events in fd_events: readable = None writable = None if events & inmask: readable = functools.partial(activate, fd, inmask) if events & outmask: writable = functools.partial(activate, fd, outmask) callback_refs[fd] = (readable, writable) poll_regs[fd] = scheduler._register_fd(fd, readable, writable) if timeout: waketime = time.time() + timeout scheduler.pause_until(waketime) elif timeout == 0: scheduler.pause() else: scheduler.state.mainloop.switch() for fd, reg in poll_regs.iteritems(): readable, writable = callback_refs[fd] scheduler._unregister_fd(fd, readable, writable, reg) if scheduler.state.interrupted: raise IOError(errno.EINTR, "interrupted system call") return activated.items()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'processAndSetDefaults'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '17', '37', '44', '51', '69']},{'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': 'input'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'raise_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'NO_INPUT_FILE'},{'id': '17', 'type': 'if_statement', 'children': ['18', '22', '34']},{'id': '18', 'type': 'not_operator', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '22', 'type': 'block', 'children': ['23', '33']},{'id': '23', 'type': 'if_statement', 'children': ['24', '28']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'build_directory'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'pass_statement', 'children': []},{'id': '34', 'type': 'else_clause', 'children': ['35']},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'pass_statement', 'children': []},{'id': '37', 'type': 'if_statement', 'children': ['38', '42']},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'build_directory'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'pass_statement', 'children': []},{'id': '44', 'type': 'for_statement', 'children': ['45', '46', '49']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'dependency'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'given_dependencies'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'pass_statement', 'children': []},{'id': '51', 'type': 'if_statement', 'children': ['52', '63']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': '!='},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'output_format'},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'getType'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'raise_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': '""'},{'id': '69', 'type': 'return_statement', 'children': []}
def processAndSetDefaults(self): if not self.input: raise ValueError(NO_INPUT_FILE) if not self.output: if not self.build_directory: File() pass else: pass if not self.build_directory: pass for dependency in self.given_dependencies: pass if self.output_format != self.output.getType(): raise ValueError("") return
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'schedule'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '9', 'type': 'tuple', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '37', '67', '76']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '35']},{'id': '19', 'type': 'function_definition', 'children': ['20', '21', '23']},{'id': '20', 'type': 'function_name', 'children': [], 'value': 'decorator'},{'id': '21', 'type': 'parameters', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'schedule'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29', '32']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'decorator'},{'id': '37', 'type': 'if_statement', 'children': ['38', '51', '56']},{'id': '38', 'type': 'boolean_operator', 'children': ['39', '46'], 'value': 'or'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'greenlet'},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'main_greenlet'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'glet'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '56', 'type': 'else_clause', 'children': ['57']},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'glet'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'greenlet'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '66']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'paused'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'glet'},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'target'}
def schedule(target=None, args=(), kwargs=None): if target is None: def decorator(target): return schedule(target, args=args, kwargs=kwargs) return decorator if isinstance(target, compat.greenlet) or target is compat.main_greenlet: glet = target else: glet = greenlet(target, args, kwargs) state.paused.append(glet) return target
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'schedule_at'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'unixtime'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '10', 'type': 'tuple', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '39', '69', '79']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '37']},{'id': '20', 'type': 'function_definition', 'children': ['21', '22', '24']},{'id': '21', 'type': 'function_name', 'children': [], 'value': 'decorator'},{'id': '22', 'type': 'parameters', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'target'},{'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': 'schedule_at'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31', '34']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'unixtime'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'decorator'},{'id': '39', 'type': 'if_statement', 'children': ['40', '53', '58']},{'id': '40', 'type': 'boolean_operator', 'children': ['41', '48'], 'value': 'or'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'greenlet'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'main_greenlet'},{'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': 'glet'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '58', 'type': 'else_clause', 'children': ['59']},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'glet'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'greenlet'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67', '68']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'timed_paused'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'unixtime'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'glet'},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'target'}
def schedule_at(unixtime, target=None, args=(), kwargs=None): if target is None: def decorator(target): return schedule_at(unixtime, target, args=args, kwargs=kwargs) return decorator if isinstance(target, compat.greenlet) or target is compat.main_greenlet: glet = target else: glet = greenlet(target, args, kwargs) state.timed_paused.insert(unixtime, glet) return target
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'schedule_recurring'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'maxtimes'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'starting_at'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '16', 'type': 'tuple', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '31', '53', '57', '88', '130', '136', '147']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'starting_at'},{'id': '24', 'type': 'boolean_operator', 'children': ['25', '26'], 'value': 'or'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'starting_at'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'if_statement', 'children': ['32', '35']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'block', 'children': ['36', '51']},{'id': '36', 'type': 'function_definition', 'children': ['37', '38', '40']},{'id': '37', 'type': 'function_name', 'children': [], 'value': 'decorator'},{'id': '38', 'type': 'parameters', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'schedule_recurring'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47', '48', '49', '50']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'maxtimes'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'starting_at'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'decorator'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '57', 'type': 'if_statement', 'children': ['58', '71']},{'id': '58', 'type': 'boolean_operator', 'children': ['59', '66'], 'value': 'or'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'greenlet'},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'is'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'main_greenlet'},{'id': '71', 'type': 'block', 'children': ['72', '82']},{'id': '72', 'type': 'if_statement', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dead'},{'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': 'TypeError'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'string', 'children': [], 'value': '"can\'t schedule a dead greenlet"'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '88', 'type': 'function_definition', 'children': ['89', '90', '93']},{'id': '89', 'type': 'function_name', 'children': [], 'value': 'run_and_schedule_one'},{'id': '90', 'type': 'parameters', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'tstamp'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'if_statement', 'children': ['95', '101']},{'id': '95', 'type': 'boolean_operator', 'children': ['96', '98'], 'value': 'or'},{'id': '96', 'type': 'not_operator', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'maxtimes'},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': '<'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'maxtimes'},{'id': '101', 'type': 'block', 'children': ['102', '106', '117']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'augmented_assignment', 'children': ['104', '105'], 'value': '+='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'tstamp'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '109', 'type': 'argument_list', 'children': ['110', '112']},{'id': '110', 'type': 'list_splat', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '112', 'type': 'dictionary_splat', 'children': ['113']},{'id': '113', 'type': '()', 'children': ['114']},{'id': '114', 'type': 'boolean_operator', 'children': ['115', '116'], 'value': 'or'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '116', 'type': 'dictionary', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'schedule_at'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122', '123']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'tstamp'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'run_and_schedule_one'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '125', 'type': 'tuple', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'tstamp'},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '+'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '129', 'type': 'integer', 'children': [], 'value': '1'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'firstrun'},{'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '+'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'starting_at'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'schedule_at'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141', '142']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'firstrun'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'run_and_schedule_one'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '144', 'type': 'tuple', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'firstrun'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'return_statement', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'target'}
def schedule_recurring(interval, target=None, maxtimes=0, starting_at=0, args=(), kwargs=None): starting_at = starting_at or time.time() if target is None: def decorator(target): return schedule_recurring( interval, target, maxtimes, starting_at, args, kwargs) return decorator func = target if isinstance(target, compat.greenlet) or target is compat.main_greenlet: if target.dead: raise TypeError("can't schedule a dead greenlet") func = target.run def run_and_schedule_one(tstamp, count): if not maxtimes or count < maxtimes: tstamp += interval func(*args, **(kwargs or {})) schedule_at(tstamp, run_and_schedule_one, args=(tstamp, count + 1)) firstrun = starting_at + interval schedule_at(firstrun, run_and_schedule_one, args=(firstrun, 0)) return target
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'assert_output'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'assert_equal'},{'id': '6', 'type': 'block', 'children': ['7', '14', '21']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted_output'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorted_assert'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'assert_equal'},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': '!='},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sorted_output'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sorted_assert'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'raise_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ASSERT_ERROR'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorted_output'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted_assert'}
def assert_output(output, assert_equal): sorted_output = sorted(output) sorted_assert = sorted(assert_equal) if sorted_output != sorted_assert: raise ValueError(ASSERT_ERROR.format(sorted_output, sorted_assert))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_input'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '6', 'type': 'keyword_separator', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'redo_prompt'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'repeat_prompt'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '26', '30', '56', '70', '95', '142', '149', '175']},{'id': '14', 'type': 'if_statement', 'children': ['15', '20']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '24', 'type': 'tuple', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'to_join'},{'id': '29', 'type': 'list', 'children': [], 'value': '[]'},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '33']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'if_statement', 'children': ['35', '36', '47']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'item'},{'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': 'to_join'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '47', 'type': 'else_clause', 'children': ['48']},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'to_join'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'string', 'children': [], 'value': '"\'\'"'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'augmented_assignment', 'children': ['58', '59'], 'value': '+='},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'string', 'children': [], 'value': '" [{}]: "'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'to_join'},{'id': '70', 'type': 'if_statement', 'children': ['71', '72', '77']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'repeat_prompt'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'redo_prompt'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '77', 'type': 'elif_clause', 'children': ['78', '80']},{'id': '78', 'type': 'not_operator', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'redo_prompt'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'redo_prompt'},{'id': '84', 'type': 'call', 'children': ['85', '90']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'concatenated_string', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': '"Incorrect input, please choose from {}: "'},{'id': '88', 'type': 'string', 'children': [], 'value': '""'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '95', 'type': 'if_statement', 'children': ['96', '100', '111', '127']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'function_definition', 'children': ['102', '103', '105']},{'id': '102', 'type': 'function_name', 'children': [], 'value': '_checker'},{'id': '103', 'type': 'parameters', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '111', 'type': 'elif_clause', 'children': ['112', '117']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'function_definition', 'children': ['119', '120', '122']},{'id': '119', 'type': 'function_name', 'children': [], 'value': '_checker'},{'id': '120', 'type': 'parameters', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'return_statement', 'children': ['124']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'in'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '127', 'type': 'else_clause', 'children': ['128']},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'raise_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'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': 'RESPONSES_ERROR'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '149', 'type': 'while_statement', 'children': ['150', '155']},{'id': '150', 'type': 'not_operator', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': '_checker'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '155', 'type': 'block', 'children': ['156', '165']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'conditional_expression', 'children': ['172', '173', '174'], 'value': 'if'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'redo_prompt'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'redo_prompt'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '175', 'type': 'return_statement', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'response'}
def get_input(prompt, check, *, redo_prompt=None, repeat_prompt=False): if isinstance(check, str): check = (check,) to_join = [] for item in check: if item: to_join.append(str(item)) else: to_join.append("''") prompt += " [{}]: ".format('/'.join(to_join)) if repeat_prompt: redo_prompt = prompt elif not redo_prompt: redo_prompt = "Incorrect input, please choose from {}: " \ "".format(str(check)) if callable(check): def _checker(r): return check(r) elif isinstance(check, tuple): def _checker(r): return r in check else: raise ValueError(RESPONSES_ERROR.format(type(check))) response = input(prompt) while not _checker(response): print(response, type(response)) response = input(redo_prompt if redo_prompt else prompt) return response
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'install_build_requires'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'pkg_targets'},{'id': '5', 'type': 'block', 'children': ['6', '45', '103']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '13']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'pip_install'},{'id': '8', 'type': 'parameters', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '25', '29']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'pkg_name_version'},{'id': '17', 'type': 'conditional_expression', 'children': ['18', '23', '24'], 'value': 'if'},{'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '%'},{'id': '19', 'type': 'string', 'children': [], 'value': "'%s==%s'"},{'id': '20', 'type': 'tuple', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '25', 'type': 'print_statement', 'children': ['26']},{'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '%'},{'id': '27', 'type': 'string', 'children': [], 'value': '\'[WARNING] %s not found, attempting to install using a raw "pip install" call!\''},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'pkg_name_version'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '44']},{'id': '31', 'type': 'attribute', 'children': ['32', '43']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '36', 'type': 'argument_list', 'children': ['37', '40']},{'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '%'},{'id': '38', 'type': 'string', 'children': [], 'value': "'pip install %s'"},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'pkg_name_version'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '42', 'type': 'True', 'children': []},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'communicate'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'function_definition', 'children': ['46', '47', '49']},{'id': '46', 'type': 'function_name', 'children': [], 'value': 'get_pkg_info'},{'id': '47', 'type': 'parameters', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'pkg'},{'id': '49', 'type': 'block', 'children': ['50', '58', '99']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '55']},{'id': '52', 'type': 'pattern_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '55', 'type': 'expression_list', 'children': ['56', '57']},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'None', 'children': []},{'id': '58', 'type': 'if_statement', 'children': ['59', '62', '74']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'in'},{'id': '60', 'type': 'string', 'children': [], 'value': "'=='"},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'pkg'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'pattern_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'pkg'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': "'=='"},{'id': '74', 'type': 'else_clause', 'children': ['75']},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '79', 'type': 'subscript', 'children': ['80', '98']},{'id': '80', 'type': 'call', 'children': ['81', '96']},{'id': '81', 'type': 'attribute', 'children': ['82', '95']},{'id': '82', 'type': 'call', 'children': ['83', '92']},{'id': '83', 'type': 'attribute', 'children': ['84', '91']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'pkg'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': "'>'"},{'id': '90', 'type': 'string', 'children': [], 'value': "''"},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'<'"},{'id': '94', 'type': 'string', 'children': [], 'value': "''"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'string', 'children': [], 'value': "'='"},{'id': '98', 'type': 'integer', 'children': [], 'value': '0'},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'expression_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '103', 'type': 'for_statement', 'children': ['104', '105', '106']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'pkg'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'pkg_targets'},{'id': '106', 'type': 'block', 'children': ['107', '116']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'pattern_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'get_pkg_info'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'pkg'},{'id': '116', 'type': 'try_statement', 'children': ['117', '165']},{'id': '117', 'type': 'block', 'children': ['118', '129']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'pkg_name_version'},{'id': '121', 'type': 'conditional_expression', 'children': ['122', '127', '128'], 'value': 'if'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '%'},{'id': '123', 'type': 'string', 'children': [], 'value': "'%s==%s'"},{'id': '124', 'type': 'tuple', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '129', 'type': 'if_statement', 'children': ['130', '131', '156']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '131', 'type': 'block', 'children': ['132', '145']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '137', 'type': 'argument_list', 'children': ['138', '144']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'importlib'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'import_module'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '144', 'type': 'string', 'children': [], 'value': "'__version__'"},{'id': '145', 'type': 'if_statement', 'children': ['146', '149']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '!='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'pip_install'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'},{'id': '156', 'type': 'else_clause', 'children': ['157']},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'importlib'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'import_module'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '165', 'type': 'except_clause', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'pip_install'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'pkg_name'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'pkg_vers'}
def install_build_requires(pkg_targets): def pip_install(pkg_name, pkg_vers=None): pkg_name_version = '%s==%s' % (pkg_name, pkg_vers) if pkg_vers else pkg_name print '[WARNING] %s not found, attempting to install using a raw "pip install" call!' % pkg_name_version subprocess.Popen('pip install %s' % pkg_name_version, shell=True).communicate() def get_pkg_info(pkg): pkg_name, pkg_vers = None, None if '==' in pkg: pkg_name, pkg_vers = pkg.split('==') else: pkg_name = pkg.replace('>', '').replace('<', '').split('=')[0] return pkg_name, pkg_vers for pkg in pkg_targets: pkg_name, pkg_vers = get_pkg_info(pkg) try: pkg_name_version = '%s==%s' % (pkg_name, pkg_vers) if pkg_vers else pkg_name if pkg_vers: version = getattr(importlib.import_module(pkg_name), '__version__') if version != pkg_vers: pip_install(pkg_name, pkg_vers) else: importlib.import_module(pkg_name) except ImportError: pip_install(pkg_name, pkg_vers)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'PackagePublishUI'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'visibility'},{'id': '7', 'type': 'block', 'children': ['8', '21', '34', '96', '117', '248', '273', '277', '319', '340']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'linux_lst'},{'id': '11', 'type': 'dictionary', 'children': ['12']},{'id': '12', 'type': 'pair', 'children': ['13', '14']},{'id': '13', 'type': 'string', 'children': [], 'value': "'L'"},{'id': '14', 'type': 'dictionary', 'children': ['15', '18']},{'id': '15', 'type': 'pair', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'pair', 'children': ['19', '20']},{'id': '19', 'type': 'string', 'children': [], 'value': "'Description'"},{'id': '20', 'type': 'string', 'children': [], 'value': "'All Linux'"},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'windows_lst'},{'id': '24', 'type': 'dictionary', 'children': ['25']},{'id': '25', 'type': 'pair', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'W'"},{'id': '27', 'type': 'dictionary', 'children': ['28', '31']},{'id': '28', 'type': 'pair', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '30', 'type': 'False', 'children': []},{'id': '31', 'type': 'pair', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "'Description'"},{'id': '33', 'type': 'string', 'children': [], 'value': "'All Windows'"},{'id': '34', 'type': 'for_statement', 'children': ['35', '36', '45']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '36', 'type': 'call', 'children': ['37', '44']},{'id': '37', 'type': 'attribute', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'v1'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'Server'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'GetTemplates'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'block', 'children': ['46', '52']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '51']},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '50', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '51', 'type': 'False', 'children': []},{'id': '52', 'type': 'if_statement', 'children': ['53', '62', '74']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': '"Windows"'},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '61', 'type': 'string', 'children': [], 'value': "'Description'"},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '73']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'windows_lst'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '72', 'type': 'string', 'children': [], 'value': "'OperatingSystem'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '74', 'type': 'elif_clause', 'children': ['75', '84']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'string', 'children': [], 'value': '"CentOS|RedHat|Ubuntu"'},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '83', 'type': 'string', 'children': [], 'value': "'Description'"},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '95']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'linux_lst'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '94', 'type': 'string', 'children': [], 'value': "'OperatingSystem'"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '96', 'type': 'if_statement', 'children': ['97', '102']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '101'], 'value': '=='},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '101', 'type': 'string', 'children': [], 'value': "'posix'"},{'id': '102', 'type': 'block', 'children': ['103', '111']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'scr'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'curses'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'initscr'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'curses'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'cbreak'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'while_statement', 'children': ['118', '119']},{'id': '118', 'type': 'True', 'children': []},{'id': '119', 'type': 'block', 'children': ['120', '150']},{'id': '120', 'type': 'if_statement', 'children': ['121', '126', '138']},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '125'], 'value': '=='},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '125', 'type': 'string', 'children': [], 'value': "'posix'"},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'Blueprint'},{'id': '133', 'type': 'identifier', 'children': [], 'value': '_DrawPublishPackageUIPosix'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136', '137']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'scr'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'linux_lst'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'windows_lst'},{'id': '138', 'type': 'else_clause', 'children': ['139']},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'Blueprint'},{'id': '146', 'type': 'identifier', 'children': [], 'value': '_DrawPublishPackageUI'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'linux_lst'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'windows_lst'},{'id': '150', 'type': 'if_statement', 'children': ['151', '158', '160', '186', '212', '230']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '157'], 'value': '=='},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '156', 'type': 'argument_list', 'children': []},{'id': '157', 'type': 'string', 'children': [], 'value': "'q'"},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'break_statement', 'children': []},{'id': '160', 'type': 'elif_clause', 'children': ['161', '168']},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '167'], 'value': '=='},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '166', 'type': 'argument_list', 'children': []},{'id': '167', 'type': 'string', 'children': [], 'value': "'l'"},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '172']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'linux_lst'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '180']},{'id': '175', 'type': 'subscript', 'children': ['176', '179']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'linux_lst'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '179', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '180', 'type': 'not_operator', 'children': ['181']},{'id': '181', 'type': 'subscript', 'children': ['182', '185']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'linux_lst'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '185', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '186', 'type': 'elif_clause', 'children': ['187', '194']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '193'], 'value': '=='},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'for_statement', 'children': ['196', '197', '198']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'windows_lst'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '206']},{'id': '201', 'type': 'subscript', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'windows_lst'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '205', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '206', 'type': 'not_operator', 'children': ['207']},{'id': '207', 'type': 'subscript', 'children': ['208', '211']},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'windows_lst'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '211', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '212', 'type': 'elif_clause', 'children': ['213', '216']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': 'in'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'linux_lst'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '224']},{'id': '219', 'type': 'subscript', 'children': ['220', '223']},{'id': '220', 'type': 'subscript', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'linux_lst'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '223', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '224', 'type': 'not_operator', 'children': ['225']},{'id': '225', 'type': 'subscript', 'children': ['226', '229']},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'linux_lst'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '229', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '230', 'type': 'elif_clause', 'children': ['231', '234']},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': 'in'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'windows_lst'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '242']},{'id': '237', 'type': 'subscript', 'children': ['238', '241']},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'windows_lst'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '241', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '242', 'type': 'not_operator', 'children': ['243']},{'id': '243', 'type': 'subscript', 'children': ['244', '247']},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'windows_lst'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '247', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '248', 'type': 'if_statement', 'children': ['249', '254']},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '253'], 'value': '=='},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '253', 'type': 'string', 'children': [], 'value': "'posix'"},{'id': '254', 'type': 'block', 'children': ['255', '261', '267']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'curses'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'nocbreak'},{'id': '260', 'type': 'argument_list', 'children': []},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'curses'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '266', 'type': 'argument_list', 'children': []},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'curses'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'endwin'},{'id': '272', 'type': 'argument_list', 'children': []},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '276', 'type': 'list', 'children': [], 'value': '[]'},{'id': '277', 'type': 'for_statement', 'children': ['278', '279', '297']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '279', 'type': 'call', 'children': ['280', '296']},{'id': '280', 'type': 'attribute', 'children': ['281', '295']},{'id': '281', 'type': 'call', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'binary_operator', 'children': ['285', '290'], 'value': '+'},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'linux_lst'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '289', 'type': 'argument_list', 'children': []},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'windows_lst'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '294', 'type': 'argument_list', 'children': []},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '296', 'type': 'argument_list', 'children': []},{'id': '297', 'type': 'block', 'children': ['298']},{'id': '298', 'type': 'if_statement', 'children': ['299', '306']},{'id': '299', 'type': 'boolean_operator', 'children': ['300', '303'], 'value': 'and'},{'id': '300', 'type': 'subscript', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '302', 'type': 'string', 'children': [], 'value': "'selected'"},{'id': '303', 'type': 'comparison_operator', 'children': ['304', '305'], 'value': 'in'},{'id': '304', 'type': 'string', 'children': [], 'value': "'OperatingSystem'"},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '306', 'type': 'block', 'children': ['307']},{'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': 'ids'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'subscript', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '318', 'type': 'string', 'children': [], 'value': "'OperatingSystem'"},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '328']},{'id': '321', 'type': 'attribute', 'children': ['322', '327']},{'id': '322', 'type': 'attribute', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'clc'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'v1'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'Status'},{'id': '328', 'type': 'argument_list', 'children': ['329', '330', '331']},{'id': '329', 'type': 'string', 'children': [], 'value': "'SUCCESS'"},{'id': '330', 'type': 'integer', 'children': [], 'value': '2'},{'id': '331', 'type': 'binary_operator', 'children': ['332', '333'], 'value': '%'},{'id': '332', 'type': 'string', 'children': [], 'value': "'Selected operating system IDs: %s'"},{'id': '333', 'type': '()', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'string', 'children': [], 'value': '" "'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '340', 'type': 'return_statement', 'children': ['341']},{'id': '341', 'type': '()', 'children': ['342']},{'id': '342', 'type': 'call', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'Blueprint'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'PackagePublish'},{'id': '346', 'type': 'argument_list', 'children': ['347', '348', '349', '350']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'visibility'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'ids'}
def PackagePublishUI(package,type,visibility): linux_lst = {'L': {'selected': False, 'Description': 'All Linux'}} windows_lst = {'W': {'selected': False, 'Description': 'All Windows'}} for r in clc.v1.Server.GetTemplates(): r['selected'] = False if re.search("Windows",r['Description']): windows_lst[str(r['OperatingSystem'])] = r elif re.search("CentOS|RedHat|Ubuntu",r['Description']): linux_lst[str(r['OperatingSystem'])] = r if os.name=='posix': scr = curses.initscr() curses.cbreak(); while True: if os.name=='posix': c = Blueprint._DrawPublishPackageUIPosix(scr,linux_lst,windows_lst) else: c = Blueprint._DrawPublishPackageUI(linux_lst,windows_lst) if c.lower() == 'q': break elif c.lower() == 'l': for l in linux_lst: linux_lst[l]['selected'] = not linux_lst[l]['selected'] elif c.lower() == 'w': for l in windows_lst: windows_lst[l]['selected'] = not windows_lst[l]['selected'] elif c in linux_lst: linux_lst[c]['selected'] = not linux_lst[c]['selected'] elif c in windows_lst: windows_lst[c]['selected'] = not windows_lst[c]['selected'] if os.name=='posix': curses.nocbreak(); curses.echo(); curses.endwin() ids = [] for l in dict(linux_lst.items()+windows_lst.items()).values(): if l['selected'] and 'OperatingSystem' in l: ids.append(str(l['OperatingSystem'])) clc.v1.output.Status('SUCCESS',2,'Selected operating system IDs: %s' % (" ".join(ids))) return(Blueprint.PackagePublish(package,type,visibility,ids))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_construct_select_query'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'dictionary_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '6', 'type': 'block', 'children': ['7', '16', '26', '36', '46', '58', '109', '226', '235', '249', '263']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'table_name'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': "'table'"},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'distinct'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'distinct'"},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'select_count'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '35', 'type': 'False', 'children': []},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '39'], 'value': 'and'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'distinct'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'select_count'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'raise_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'UnsupportedDefinitionError'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': "'SELECT (DISTINCT ...) is not supported'"},{'id': '46', 'type': 'if_statement', 'children': ['47', '52']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '49'], 'value': 'and'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'select_count'},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'},{'id': '50', 'type': 'string', 'children': [], 'value': "'select'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'raise_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'UnsupportedDefinitionError'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': "'SELECT COUNT(columns) is not supported'"},{'id': '58', 'type': 'if_statement', 'children': ['59', '62']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'in'},{'id': '60', 'type': 'string', 'children': [], 'value': "'joins'"},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '62', 'type': 'block', 'children': ['63', '72', '87', '93']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'join_definitions'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': "'joins'"},{'id': '72', 'type': 'if_statement', 'children': ['73', '81']},{'id': '73', 'type': 'not_operator', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'join_definitions'},{'id': '78', 'type': 'tuple', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'join_definitions'},{'id': '85', 'type': 'tuple', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'join_definitions'},{'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': 'filter_definition'},{'id': '91', 'type': 'string', 'children': [], 'value': "'joins'"},{'id': '92', 'type': 'list', 'children': [], 'value': '[]'},{'id': '93', 'type': 'for_statement', 'children': ['94', '95', '96']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'join_def'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'join_definitions'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '104']},{'id': '99', 'type': 'attribute', 'children': ['100', '103']},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '102', 'type': 'string', 'children': [], 'value': "'joins'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_expand_join'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'join_def'},{'id': '109', 'type': 'if_statement', 'children': ['110', '113']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'in'},{'id': '111', 'type': 'string', 'children': [], 'value': "'where'"},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'for_statement', 'children': ['115', '118', '125']},{'id': '115', 'type': 'pattern_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '118', 'type': 'call', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '122', 'type': 'string', 'children': [], 'value': "'where'"},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'if_statement', 'children': ['127', '131', '171']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'is_filter_query'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '131', 'type': 'block', 'children': ['132', '141', '151']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sub_query'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_FILTER_KEY'},{'id': '141', 'type': 'if_statement', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'raise_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'ParsingInputError'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '%'},{'id': '149', 'type': 'string', 'children': [], 'value': '"Unknown keys for sub-query provided: %s"'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '158']},{'id': '153', 'type': 'subscript', 'children': ['154', '157']},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '156', 'type': 'string', 'children': [], 'value': "'where'"},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'mosql_raw'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'string', 'children': [], 'value': "'( {} )'"},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': '_construct_select_query'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'dictionary_splat', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sub_query'},{'id': '171', 'type': 'elif_clause', 'children': ['172', '195']},{'id': '172', 'type': 'boolean_operator', 'children': ['173', '185'], 'value': 'and'},{'id': '173', 'type': 'boolean_operator', 'children': ['174', '179'], 'value': 'and'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'string', 'children': [], 'value': "'$'"},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'QUERY_REFERENCE'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'fullmatch'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '192', 'type': 'slice', 'children': ['193', '194']},{'id': '193', 'type': 'integer', 'children': [], 'value': '1'},{'id': '194', 'type': 'colon', 'children': []},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '203']},{'id': '198', 'type': 'subscript', 'children': ['199', '202']},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '201', 'type': 'string', 'children': [], 'value': "'where'"},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'mosql_raw'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'string', 'children': [], 'value': '\'"{}"\''},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'string', 'children': [], 'value': '\'"."\''},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '224']},{'id': '217', 'type': 'attribute', 'children': ['218', '223']},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '220', 'type': 'slice', 'children': ['221', '222']},{'id': '221', 'type': 'integer', 'children': [], 'value': '1'},{'id': '222', 'type': 'colon', 'children': []},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'raw_select'},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '231', 'type': 'argument_list', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'table_name'},{'id': '233', 'type': 'dictionary_splat', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'filter_definition'},{'id': '235', 'type': 'if_statement', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'distinct'},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'raw_select'},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'raw_select'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '245', 'type': 'argument_list', 'children': ['246', '247', '248']},{'id': '246', 'type': 'string', 'children': [], 'value': "'SELECT'"},{'id': '247', 'type': 'string', 'children': [], 'value': "'SELECT DISTINCT'"},{'id': '248', 'type': 'integer', 'children': [], 'value': '1'},{'id': '249', 'type': 'if_statement', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'select_count'},{'id': '251', 'type': 'block', 'children': ['252']},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'raw_select'},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'raw_select'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '259', 'type': 'argument_list', 'children': ['260', '261', '262']},{'id': '260', 'type': 'string', 'children': [], 'value': "'SELECT *'"},{'id': '261', 'type': 'string', 'children': [], 'value': "'SELECT COUNT(*)'"},{'id': '262', 'type': 'integer', 'children': [], 'value': '1'},{'id': '263', 'type': 'return_statement', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'raw_select'}
def _construct_select_query(**filter_definition): table_name = filter_definition.pop('table') distinct = filter_definition.pop('distinct', False) select_count = filter_definition.pop('count', False) if distinct and select_count: raise UnsupportedDefinitionError('SELECT (DISTINCT ...) is not supported') if select_count and 'select' in filter_definition: raise UnsupportedDefinitionError('SELECT COUNT(columns) is not supported') if 'joins' in filter_definition: join_definitions = filter_definition.pop('joins') if not isinstance(join_definitions, (tuple, list)): join_definitions = (join_definitions,) filter_definition['joins'] = [] for join_def in join_definitions: filter_definition['joins'].append(_expand_join(join_def)) if 'where' in filter_definition: for key, value in filter_definition['where'].items(): if is_filter_query(value): sub_query = value.pop(DEFAULT_FILTER_KEY) if value: raise ParsingInputError("Unknown keys for sub-query provided: %s" % value) filter_definition['where'][key] = mosql_raw('( {} )'.format(_construct_select_query(**sub_query))) elif isinstance(value, str) and value.startswith('$') and QUERY_REFERENCE.fullmatch(value[1:]): filter_definition['where'][key] = mosql_raw('"{}"'.format('"."'.join(value[1:].split('.')))) raw_select = select(table_name, **filter_definition) if distinct: raw_select = raw_select.replace('SELECT', 'SELECT DISTINCT', 1) if select_count: raw_select = raw_select.replace('SELECT *', 'SELECT COUNT(*)', 1) return raw_select
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'encode'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '7', 'type': 'string', 'children': [], 'value': "'utf8'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '10', 'type': 'integer', 'children': [], 'value': '1'},{'id': '11', 'type': 'block', 'children': ['12', '38', '304', '313']},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': '>'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'block', 'children': ['17', '32']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'pbar'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'progressbar'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ProgressBar'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '27', 'type': 'subscript', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '31', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'pbar'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'for_statement', 'children': ['39', '42', '48']},{'id': '39', 'type': 'pattern_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'colnum'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'if_statement', 'children': ['50', '59']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '52', 'type': 'argument_list', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '59', 'type': 'block', 'children': ['60', '70']},{'id': '60', 'type': 'if_statement', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'pbar'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'colnum'},{'id': '70', 'type': 'if_statement', 'children': ['71', '110']},{'id': '71', 'type': 'boolean_operator', 'children': ['72', '97'], 'value': 'and'},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '78'], 'value': 'in'},{'id': '73', 'type': 'attribute', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '78', 'type': 'tuple', 'children': ['79', '85', '91']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': "'object'"},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'string', 'children': [], 'value': "'U'"},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'string', 'children': [], 'value': "'S'"},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '99', 'type': 'generator_expression', 'children': ['100', '105']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '105', 'type': 'for_in_clause', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '110', 'type': 'block', 'children': ['111', '130', '140', '298']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'strmask'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'list_comprehension', 'children': ['120', '125']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '125', 'type': 'for_in_clause', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '133', 'type': 'call', 'children': ['134', '139']},{'id': '134', 'type': 'attribute', 'children': ['135', '138']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '139', 'type': 'argument_list', 'children': []},{'id': '140', 'type': 'try_statement', 'children': ['141', '164', '198']},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '147']},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'strmask'},{'id': '147', 'type': 'call', 'children': ['148', '153']},{'id': '148', 'type': 'attribute', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '162']},{'id': '155', 'type': 'attribute', 'children': ['156', '161']},{'id': '156', 'type': 'attribute', 'children': ['157', '160']},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'strmask'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'string', 'children': [], 'value': "'U'"},{'id': '164', 'type': 'except_clause', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '166', 'type': 'block', 'children': ['167', '197']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'string', 'children': [], 'value': '"Unable to convert {} elements starting at position {} in column {}"'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '175', 'type': 'argument_list', 'children': ['176', '180', '196']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'strmask'},{'id': '180', 'type': 'subscript', 'children': ['181', '193']},{'id': '181', 'type': 'list_comprehension', 'children': ['182', '183', '191']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '183', 'type': 'for_in_clause', 'children': ['184', '187']},{'id': '184', 'type': 'pattern_list', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'strmask'},{'id': '191', 'type': 'if_clause', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '193', 'type': 'slice', 'children': ['194', '195']},{'id': '194', 'type': 'colon', 'children': []},{'id': '195', 'type': 'integer', 'children': [], 'value': '1'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '197', 'type': 'raise_statement', 'children': []},{'id': '198', 'type': 'except_clause', 'children': ['199', '202']},{'id': '199', 'type': 'tuple', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'UnicodeEncodeError'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'try_statement', 'children': ['204', '227']},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '210']},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'strmask'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'list_comprehension', 'children': ['216', '222']},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'eval'},{'id': '218', 'type': 'argument_list', 'children': ['219', '220', '221']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '220', 'type': 'dictionary', 'children': []},{'id': '221', 'type': 'dictionary', 'children': []},{'id': '222', 'type': 'for_in_clause', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'strmask'},{'id': '227', 'type': 'except_clause', 'children': ['228', '232']},{'id': '228', 'type': 'tuple', 'children': ['229', '230', '231']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'UnicodeEncodeError'},{'id': '232', 'type': 'block', 'children': ['233', '237', '282']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'newseries'},{'id': '236', 'type': 'list', 'children': [], 'value': '[]'},{'id': '237', 'type': 'for_statement', 'children': ['238', '239', '242']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'strmask'},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'try_statement', 'children': ['244', '255']},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'augmented_assignment', 'children': ['247', '248'], 'value': '+='},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'newseries'},{'id': '248', 'type': 'list', 'children': ['249'], 'value': "[s.encode('utf8')]"},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'string', 'children': [], 'value': "'utf8'"},{'id': '255', 'type': 'except_clause', 'children': ['256']},{'id': '256', 'type': 'block', 'children': ['257', '274']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'string', 'children': [], 'value': "u'Had trouble encoding {} so used repr to turn it into {}'"},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '265', 'type': 'argument_list', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'transcode_unicode'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'augmented_assignment', 'children': ['276', '277'], 'value': '+='},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'newseries'},{'id': '277', 'type': 'list', 'children': ['278'], 'value': '[transcode_unicode(s)]'},{'id': '278', 'type': 'call', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'transcode_unicode'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '287']},{'id': '284', 'type': 'subscript', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'strmask'},{'id': '287', 'type': 'call', 'children': ['288', '296']},{'id': '288', 'type': 'attribute', 'children': ['289', '295']},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'newseries'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'string', 'children': [], 'value': "'O'"},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '303']},{'id': '300', 'type': 'subscript', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '304', 'type': 'if_statement', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '306', 'type': 'block', 'children': ['307']},{'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': 'pbar'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'finish'},{'id': '312', 'type': 'argument_list', 'children': []},{'id': '313', 'type': 'return_statement', 'children': ['314']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'df'}
def encode(df, encoding='utf8', verbosity=1): if verbosity > 0: pbar = progressbar.ProgressBar(maxval=df.shape[1]) pbar.start() for colnum, col in enumerate(df.columns): if isinstance(df[col], pd.Series): if verbosity: pbar.update(colnum) if df[col].dtype in (np.dtype('object'), np.dtype('U'), np.dtype('S')) and any(isinstance(obj, basestring) for obj in df[col]): strmask = np.array([isinstance(obj, basestring) for obj in df[col]]) series = df[col].copy() try: series[strmask] = np.char.encode(series[strmask].values.astype('U')) except TypeError: print("Unable to convert {} elements starting at position {} in column {}".format( sum(strmask), [i for i, b in enumerate(strmask) if b][:1], col)) raise except (UnicodeDecodeError, UnicodeEncodeError): try: series[strmask] = np.array([eval(s, {}, {}) for s in series[strmask]]) except (SyntaxError, UnicodeDecodeError, UnicodeEncodeError): newseries = [] for s in series[strmask]: try: newseries += [s.encode('utf8')] except: print(u'Had trouble encoding {} so used repr to turn it into {}'.format(s, repr(transcode_unicode(s)))) newseries += [transcode_unicode(s)] series[strmask] = np.array(newseries).astype('O') df[col] = series if verbosity: pbar.finish() return df
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'data_worker'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'dictionary_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '6', 'type': 'block', 'children': ['7', '181', '185']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11', '174']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'is'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '30', '48', '66', '94', '137']},{'id': '12', 'type': 'if_statement', 'children': ['13', '16', '23']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'in'},{'id': '14', 'type': 'string', 'children': [], 'value': '"function"'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'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': 'function'},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'string', 'children': [], 'value': '"function"'},{'id': '23', 'type': 'else_clause', 'children': ['24']},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': '"Invalid arguments, no function specified"'},{'id': '30', 'type': 'if_statement', 'children': ['31', '34', '41']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'},{'id': '32', 'type': 'string', 'children': [], 'value': '"input"'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'input_queue'},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '40', 'type': 'string', 'children': [], 'value': '"input"'},{'id': '41', 'type': 'else_clause', 'children': ['42']},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': '"Invalid Arguments, no input queue"'},{'id': '48', 'type': 'if_statement', 'children': ['49', '52', '59']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'},{'id': '50', 'type': 'string', 'children': [], 'value': '"output"'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'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': 'output_map'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '58', 'type': 'string', 'children': [], 'value': '"output"'},{'id': '59', 'type': 'else_clause', 'children': ['60']},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'string', 'children': [], 'value': '"Invalid Arguments, no output map"'},{'id': '66', 'type': 'if_statement', 'children': ['67', '70', '80']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'in'},{'id': '68', 'type': 'string', 'children': [], 'value': '"token"'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'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': 'argsdict'},{'id': '74', 'type': 'dictionary', 'children': ['75']},{'id': '75', 'type': 'pair', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': '"quandl_token"'},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '79', 'type': 'string', 'children': [], 'value': '"token"'},{'id': '80', 'type': 'else_clause', 'children': ['81']},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'if_statement', 'children': ['83', '88']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'in'},{'id': '84', 'type': 'string', 'children': [], 'value': '"Quandl"'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '87', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': '"Invalid Arguments, no Quandl token"'},{'id': '94', 'type': 'if_statement', 'children': ['95', '103', '123']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '102'], 'value': 'in'},{'id': '96', 'type': '()', 'children': ['97']},{'id': '97', 'type': 'boolean_operator', 'children': ['98', '101'], 'value': 'and'},{'id': '98', 'type': 'boolean_operator', 'children': ['99', '100'], 'value': 'and'},{'id': '99', 'type': 'string', 'children': [], 'value': '"source"'},{'id': '100', 'type': 'string', 'children': [], 'value': '"begin"'},{'id': '101', 'type': 'string', 'children': [], 'value': '"end"'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'argsdict'},{'id': '107', 'type': 'dictionary', 'children': ['108', '113', '118']},{'id': '108', 'type': 'pair', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': '"data_source"'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '112', 'type': 'string', 'children': [], 'value': '"source"'},{'id': '113', 'type': 'pair', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': '"begin"'},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '117', 'type': 'string', 'children': [], 'value': '"begin"'},{'id': '118', 'type': 'pair', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': '"end"'},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '122', 'type': 'string', 'children': [], 'value': '"end"'},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'if_statement', 'children': ['126', '131']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'in'},{'id': '127', 'type': 'string', 'children': [], 'value': '"pandas.io.data"'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '130', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'string', 'children': [], 'value': '"Invalid Arguments, no pandas data source specified"'},{'id': '137', 'type': 'if_statement', 'children': ['138', '150', '160']},{'id': '138', 'type': 'boolean_operator', 'children': ['139', '143'], 'value': 'and'},{'id': '139', 'type': '()', 'children': ['140']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'in'},{'id': '141', 'type': 'string', 'children': [], 'value': '"source"'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '143', 'type': '()', 'children': ['144']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '149'], 'value': 'not'},{'id': '145', 'type': '()', 'children': ['146']},{'id': '146', 'type': 'boolean_operator', 'children': ['147', '148'], 'value': 'and'},{'id': '147', 'type': 'string', 'children': [], 'value': '"begin"'},{'id': '148', 'type': 'string', 'children': [], 'value': '"end"'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'argsdict'},{'id': '154', 'type': 'dictionary', 'children': ['155']},{'id': '155', 'type': 'pair', 'children': ['156', '157']},{'id': '156', 'type': 'string', 'children': [], 'value': '"data_source"'},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '159', 'type': 'string', 'children': [], 'value': '"source"'},{'id': '160', 'type': 'else_clause', 'children': ['161']},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'if_statement', 'children': ['163', '168']},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': 'in'},{'id': '164', 'type': 'string', 'children': [], 'value': '"pandas.io.data"'},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '167', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'string', 'children': [], 'value': '"Invalid Arguments, no pandas data source specified"'},{'id': '174', 'type': 'else_clause', 'children': ['175']},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'string', 'children': [], 'value': '"Invalid Arguments"'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '184', 'type': 'integer', 'children': [], 'value': '5'},{'id': '185', 'type': 'while_statement', 'children': ['186', '192']},{'id': '186', 'type': 'not_operator', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'input_queue'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '191', 'type': 'argument_list', 'children': []},{'id': '192', 'type': 'block', 'children': ['193', '201']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'data_key'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'input_queue'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '200', 'type': 'argument_list', 'children': []},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'get_data'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207', '208', '209']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'data_key'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'output_map'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'argsdict'}
def data_worker(**kwargs): if kwargs is not None: if "function" in kwargs: function = kwargs["function"] else: Exception("Invalid arguments, no function specified") if "input" in kwargs: input_queue = kwargs["input"] else: Exception("Invalid Arguments, no input queue") if "output" in kwargs: output_map = kwargs["output"] else: Exception("Invalid Arguments, no output map") if "token" in kwargs: argsdict = {"quandl_token": kwargs["token"]} else: if "Quandl" in function.__module__: Exception("Invalid Arguments, no Quandl token") if ("source" and "begin" and "end") in kwargs: argsdict = {"data_source": kwargs["source"], "begin": kwargs["begin"], "end": kwargs["end"]} else: if "pandas.io.data" in function.__module__: Exception("Invalid Arguments, no pandas data source specified") if ("source" in kwargs) and (("begin" and "end") not in kwargs): argsdict = {"data_source": kwargs["source"]} else: if "pandas.io.data" in function.__module__: Exception("Invalid Arguments, no pandas data source specified") else: Exception("Invalid Arguments") retries = 5 while not input_queue.empty(): data_key = input_queue.get() get_data(function, data_key, output_map, retries, argsdict)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'makeproperty'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'docstring'},{'id': '13', 'type': 'string', 'children': [], 'value': "''"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'descendant'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '111', '248', '313']},{'id': '18', 'type': 'function_definition', 'children': ['19', '20', '22']},{'id': '19', 'type': 'function_name', 'children': [], 'value': 'get_property'},{'id': '20', 'type': 'parameters', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'block', 'children': ['23', '48', '64']},{'id': '23', 'type': 'if_statement', 'children': ['24', '27', '36']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '31', 'type': 'binary_operator', 'children': ['32', '33'], 'value': '%'},{'id': '32', 'type': 'string', 'children': [], 'value': "'%s:%s'"},{'id': '33', 'type': 'tuple', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '36', 'type': 'else_clause', 'children': ['37']},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '%'},{'id': '42', 'type': 'string', 'children': [], 'value': "'%s:%s'"},{'id': '43', 'type': 'tuple', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '47', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '51', 'type': 'call', 'children': ['52', '57']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_node'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'SLDNode'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_nsmap'},{'id': '64', 'type': 'if_statement', 'children': ['65', '71', '107']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '70'], 'value': '=='},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'if_statement', 'children': ['73', '76', '83']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'is'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '75', 'type': 'None', 'children': []},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'attribute', 'children': ['79', '82']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '83', 'type': 'else_clause', 'children': ['84']},{'id': '84', 'type': 'block', 'children': ['85', '94', '105']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '91', 'type': 'identifier', 'children': [], 'value': '__new__'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'cls'},{'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': 'cls'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '__init__'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101', '102']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'descendant'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'descendant'},{'id': '105', 'type': 'return_statement', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '107', 'type': 'else_clause', 'children': ['108']},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'None', 'children': []},{'id': '111', 'type': 'function_definition', 'children': ['112', '113', '116']},{'id': '112', 'type': 'function_name', 'children': [], 'value': 'set_property'},{'id': '113', 'type': 'parameters', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '116', 'type': 'block', 'children': ['117', '142', '158']},{'id': '117', 'type': 'if_statement', 'children': ['118', '121', '130']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'is'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '120', 'type': 'None', 'children': []},{'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': 'xpath'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '%'},{'id': '126', 'type': 'string', 'children': [], 'value': "'%s:%s'"},{'id': '127', 'type': 'tuple', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '130', 'type': 'else_clause', 'children': ['131']},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '%'},{'id': '136', 'type': 'string', 'children': [], 'value': "'%s:%s'"},{'id': '137', 'type': 'tuple', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '145', 'type': 'call', 'children': ['146', '151']},{'id': '146', 'type': 'attribute', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': '_node'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'SLDNode'},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_nsmap'},{'id': '158', 'type': 'if_statement', 'children': ['159', '165', '189']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '164'], 'value': '=='},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '164', 'type': 'integer', 'children': [], 'value': '1'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'if_statement', 'children': ['167', '170', '179']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'is'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '169', 'type': 'None', 'children': []},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '178']},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '176', 'type': 'integer', 'children': [], 'value': '0'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '179', 'type': 'else_clause', 'children': ['180']},{'id': '180', 'type': 'block', 'children': ['181']},{'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': 'xpath'},{'id': '185', 'type': 'integer', 'children': [], 'value': '0'},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '188', 'type': 'identifier', 'children': [], 'value': '_node'},{'id': '189', 'type': 'else_clause', 'children': ['190']},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'if_statement', 'children': ['192', '195', '235']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '194', 'type': 'None', 'children': []},{'id': '195', 'type': 'block', 'children': ['196', '220', '226']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '199', 'type': 'call', 'children': ['200', '205']},{'id': '200', 'type': 'attribute', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': '_node'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'makeelement'},{'id': '205', 'type': 'argument_list', 'children': ['206', '215']},{'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '%'},{'id': '207', 'type': 'string', 'children': [], 'value': "'{%s}%s'"},{'id': '208', 'type': 'tuple', 'children': ['209', '214']},{'id': '209', 'type': 'subscript', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'SLDNode'},{'id': '212', 'type': 'identifier', 'children': [], 'value': '_nsmap'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'nsmap'},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'SLDNode'},{'id': '219', 'type': 'identifier', 'children': [], 'value': '_nsmap'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '233']},{'id': '228', 'type': 'attribute', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '231', 'type': 'identifier', 'children': [], 'value': '_node'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '235', 'type': 'else_clause', 'children': ['236']},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '244']},{'id': '239', 'type': 'attribute', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '242', 'type': 'identifier', 'children': [], 'value': '_node'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '247', 'type': 'identifier', 'children': [], 'value': '_node'},{'id': '248', 'type': 'function_definition', 'children': ['249', '250', '252']},{'id': '249', 'type': 'function_name', 'children': [], 'value': 'del_property'},{'id': '250', 'type': 'parameters', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '252', 'type': 'block', 'children': ['253', '278', '294']},{'id': '253', 'type': 'if_statement', 'children': ['254', '257', '266']},{'id': '254', 'type': 'comparison_operator', 'children': ['255', '256'], 'value': 'is'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '256', 'type': 'None', 'children': []},{'id': '257', 'type': 'block', 'children': ['258']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '261', 'type': 'binary_operator', 'children': ['262', '263'], 'value': '%'},{'id': '262', 'type': 'string', 'children': [], 'value': "'%s:%s'"},{'id': '263', 'type': 'tuple', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '266', 'type': 'else_clause', 'children': ['267']},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '271', 'type': 'binary_operator', 'children': ['272', '273'], 'value': '%'},{'id': '272', 'type': 'string', 'children': [], 'value': "'%s:%s'"},{'id': '273', 'type': 'tuple', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '277', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '281', 'type': 'call', 'children': ['282', '287']},{'id': '282', 'type': 'attribute', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '285', 'type': 'identifier', 'children': [], 'value': '_node'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '287', 'type': 'argument_list', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '289', 'type': 'keyword_argument', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'SLDNode'},{'id': '293', 'type': 'identifier', 'children': [], 'value': '_nsmap'},{'id': '294', 'type': 'if_statement', 'children': ['295', '301']},{'id': '295', 'type': 'comparison_operator', 'children': ['296', '300'], 'value': '=='},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '300', 'type': 'integer', 'children': [], 'value': '1'},{'id': '301', 'type': 'block', 'children': ['302']},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '309']},{'id': '304', 'type': 'attribute', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '307', 'type': 'identifier', 'children': [], 'value': '_node'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'subscript', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '312', 'type': 'integer', 'children': [], 'value': '0'},{'id': '313', 'type': 'return_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '316', 'type': 'argument_list', 'children': ['317', '318', '319', '320']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'get_property'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'set_property'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'del_property'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'docstring'}
def makeproperty(ns, cls=None, name=None, docstring='', descendant=True): def get_property(self): if cls is None: xpath = '%s:%s' % (ns, name) else: xpath = '%s:%s' % (ns, cls.__name__) xpath = self._node.xpath(xpath, namespaces=SLDNode._nsmap) if len(xpath) == 1: if cls is None: return xpath[0].text else: elem = cls.__new__(cls) cls.__init__(elem, self, descendant=descendant) return elem else: return None def set_property(self, value): if cls is None: xpath = '%s:%s' % (ns, name) else: xpath = '%s:%s' % (ns, cls.__name__) xpath = self._node.xpath(xpath, namespaces=SLDNode._nsmap) if len(xpath) == 1: if cls is None: xpath[0].text = value else: xpath[0] = value._node else: if cls is None: elem = self._node.makeelement('{%s}%s' % (SLDNode._nsmap[ns], name), nsmap=SLDNode._nsmap) elem.text = value self._node.append(elem) else: self._node.append(value._node) def del_property(self): if cls is None: xpath = '%s:%s' % (ns, name) else: xpath = '%s:%s' % (ns, cls.__name__) xpath = self._node.xpath(xpath, namespaces=SLDNode._nsmap) if len(xpath) == 1: self._node.remove(xpath[0]) return property(get_property, set_property, del_property, docstring)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'ERROR', 'children': ['2', '43', '144', '161', '220']},{'id': '2', 'type': 'function_definition', 'children': ['3', '4', '6', '38']},{'id': '3', 'type': 'function_name', 'children': [], 'value': '_parse_from_string'},{'id': '4', 'type': 'parameters', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'string_input'},{'id': '6', 'type': 'ERROR', 'children': ['7', '23', '28', '29', '37']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'read_lines'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'string_input'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'read_lines'},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '28', 'type': 'ERROR', 'children': []},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'read_lines'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'else'},{'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': 'comment'},{'id': '42', 'type': 'string', 'children': [], 'value': "''"},{'id': '43', 'type': 'if_statement', 'children': ['44', '50', '66']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '49'], 'value': '>'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'read_lines'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'order'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'read_lines'},{'id': '66', 'type': 'else_clause', 'children': ['67']},{'id': '67', 'type': 'block', 'children': ['68', '90']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'read_lines'},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'read_lines'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '95', 'type': 'argument_list', 'children': ['96', '108']},{'id': '96', 'type': 'lambda', 'children': ['97', '99']},{'id': '97', 'type': 'lambda_parameters', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '104'], 'value': '=='},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '104', 'type': '()', 'children': ['105']},{'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '**'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '107', 'type': 'integer', 'children': [], 'value': '2'},{'id': '108', 'type': 'list_comprehension', 'children': ['109', '122', '135']},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'read_lines'},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'slice', 'children': ['114', '115', '116']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '115', 'type': 'colon', 'children': []},{'id': '116', 'type': '()', 'children': ['117']},{'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '+'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '**'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '121', 'type': 'integer', 'children': [], 'value': '2'},{'id': '122', 'type': 'for_in_clause', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'range_'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'read_lines'},{'id': '134', 'type': 'integer', 'children': [], 'value': '0'},{'id': '135', 'type': 'if_clause', 'children': ['136']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '143'], 'value': '=='},{'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '%'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '139', 'type': '()', 'children': ['140']},{'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '**'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '142', 'type': 'integer', 'children': [], 'value': '2'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'get_list_of_lists'},{'id': '151', 'type': 'argument_list', 'children': ['152', '155', '158']},{'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '**'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '154', 'type': 'integer', 'children': [], 'value': '2'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '**'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '157', 'type': 'integer', 'children': [], 'value': '2'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'fill_with'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'for_statement', 'children': ['162', '165', '169']},{'id': '162', 'type': 'pattern_list', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'read_lines'},{'id': '169', 'type': 'block', 'children': ['170', '178']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '177', 'type': 'argument_list', 'children': []},{'id': '178', 'type': 'for_statement', 'children': ['179', '182', '186']},{'id': '179', 'type': 'pattern_list', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'if_statement', 'children': ['188', '198', '210']},{'id': '188', 'type': 'boolean_operator', 'children': ['189', '194'], 'value': 'and'},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '206']},{'id': '201', 'type': 'subscript', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '210', 'type': 'else_clause', 'children': ['211']},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '219']},{'id': '214', 'type': 'subscript', 'children': ['215', '218']},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '219', 'type': 'integer', 'children': [], 'value': '0'},{'id': '220', 'type': 'return_statement', 'children': ['221']},{'id': '221', 'type': 'expression_list', 'children': ['222', '223', '224']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'matrix'}
def _parse_from_string(string_input): read_lines = list(filter(None, string_input.split('\n'))) if read_lines[0].startswith(' comment = read_lines.pop(0) else: comment = '' if len(read_lines) > 1: order = int(math.sqrt(len(read_lines))) else: order = int(math.sqrt(math.sqrt(len(read_lines[0])))) read_lines = filter(lambda x: len(x) == (order ** 2), [read_lines[0][i:(i + order ** 2)] for i in utils.range_(len(read_lines[0])) if i % (order ** 2) == 0]) matrix = utils.get_list_of_lists( order ** 2, order ** 2, fill_with=0) for i, line in enumerate(read_lines): line = line.strip() for j, value in enumerate(line): if value.isdigit() and int(value): matrix[i][j] = int(value) else: matrix[i][j] = 0 return order, comment, matrix
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'solve'},{'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': 'verbose'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'allow_brute_force'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '153']},{'id': '12', 'type': 'while_statement', 'children': ['13', '17']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'is_solved'},{'id': '17', 'type': 'block', 'children': ['18', '24', '40']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_update'},{'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': 'singles_found'},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '35'], 'value': 'or'},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '30'], 'value': 'or'},{'id': '29', 'type': 'False', 'children': []},{'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': '_fill_naked_singles'},{'id': '34', 'type': 'argument_list', 'children': []},{'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': '_fill_hidden_singles'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'if_statement', 'children': ['41', '43']},{'id': '41', 'type': 'not_operator', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'singles_found'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'if_statement', 'children': ['45', '46', '141']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'allow_brute_force'},{'id': '46', 'type': 'block', 'children': ['47', '51', '131', '140']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'solution'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'try_statement', 'children': ['52', '89', '113', '124']},{'id': '52', 'type': 'block', 'children': ['53', '67', '75', '82']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'dlxs'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'DancingLinksSolver'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_matrix'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'solutions'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dlxs'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'solve'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'solution'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'solutions'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'more_solutions'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'solutions'},{'id': '89', 'type': 'except_clause', 'children': ['90', '94']},{'id': '90', 'type': 'as_pattern', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '92', 'type': 'as_pattern_target', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'if_statement', 'children': ['96', '99', '106']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'is'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'solution'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_matrix'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'solution'},{'id': '106', 'type': 'else_clause', 'children': ['107']},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'raise_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'SudokuHasNoSolutionError'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'string', 'children': [], 'value': '"Dancing Links solver could not find any solution."'},{'id': '113', 'type': 'except_clause', 'children': ['114', '118']},{'id': '114', 'type': 'as_pattern', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '116', 'type': 'as_pattern_target', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'raise_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'SudokuHasNoSolutionError'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': '"Brute Force method failed."'},{'id': '124', 'type': 'else_clause', 'children': ['125']},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'raise_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'SudokuHasMultipleSolutionsError'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'string', 'children': [], 'value': '"This Sudoku has multiple solutions!"'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '138']},{'id': '133', 'type': 'attribute', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'solution_steps'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'string', 'children': [], 'value': '"BRUTE FORCE - Dancing Links"'},{'id': '140', 'type': 'break_statement', 'children': []},{'id': '141', 'type': 'else_clause', 'children': ['142']},{'id': '142', 'type': 'block', 'children': ['143', '148']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'raise_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'SudokuTooDifficultError'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'string', 'children': [], 'value': '"This Sudoku requires more advanced methods!"'},{'id': '153', 'type': 'if_statement', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '155', 'type': 'block', 'children': ['156', '172']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'string', 'children': [], 'value': '"Sudoku solved in {0} iterations!\\n{1}"'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '164', 'type': 'argument_list', 'children': ['165', '171']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'solution_steps'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'for_statement', 'children': ['173', '174', '177']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'solution_steps'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'step'}
def solve(self, verbose=False, allow_brute_force=True): while not self.is_solved: self._update() singles_found = False or self._fill_naked_singles() or self._fill_hidden_singles() if not singles_found: if allow_brute_force: solution = None try: dlxs = DancingLinksSolver(copy.deepcopy(self._matrix)) solutions = dlxs.solve() solution = next(solutions) more_solutions = next(solutions) except StopIteration as e: if solution is not None: self._matrix = solution else: raise SudokuHasNoSolutionError("Dancing Links solver could not find any solution.") except Exception as e: raise SudokuHasNoSolutionError("Brute Force method failed.") else: raise SudokuHasMultipleSolutionsError("This Sudoku has multiple solutions!") self.solution_steps.append("BRUTE FORCE - Dancing Links") break else: print(self) raise SudokuTooDifficultError("This Sudoku requires more advanced methods!") if verbose: print("Sudoku solved in {0} iterations!\n{1}".format(len(self.solution_steps), self)) for step in self.solution_steps: print(step)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_fill_hidden_singles'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '346']},{'id': '6', 'type': 'for_statement', 'children': ['7', '8', '16']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'range_'},{'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': 'side'},{'id': '16', 'type': 'block', 'children': ['17', '30']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'box_i'},{'id': '20', 'type': 'binary_operator', 'children': ['21', '27'], 'value': '*'},{'id': '21', 'type': '()', 'children': ['22']},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '//'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '40']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'range_'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '40', 'type': 'block', 'children': ['41', '54', '64', '74', '106', '151', '161', '193', '238', '248', '301']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'box_j'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '51'], 'value': '*'},{'id': '45', 'type': '()', 'children': ['46']},{'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '//'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '54', 'type': 'if_statement', 'children': ['55', '62']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '61'], 'value': '>'},{'id': '56', 'type': 'subscript', 'children': ['57', '60']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'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', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '67', 'type': 'subscript', 'children': ['68', '73']},{'id': '68', 'type': 'subscript', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_possibles'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '74', 'type': 'for_statement', 'children': ['75', '76', '84']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'range_'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '84', 'type': 'block', 'children': ['85', '91']},{'id': '85', 'type': 'if_statement', 'children': ['86', '89']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '=='},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'continue_statement', 'children': []},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'subscript', 'children': ['100', '105']},{'id': '100', 'type': 'subscript', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_possibles'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '106', 'type': 'if_statement', 'children': ['107', '113']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '112'], 'value': '=='},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'id': '113', 'type': 'block', 'children': ['114', '127', '149']},{'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': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'set_cell'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121', '122']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '134']},{'id': '129', 'type': 'attribute', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'solution_steps'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_format_step'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141', '144']},{'id': '140', 'type': 'string', 'children': [], 'value': '"HIDDEN-ROW"'},{'id': '141', 'type': 'tuple', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '144', 'type': 'subscript', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '149', 'type': 'return_statement', 'children': ['150']},{'id': '150', 'type': 'True', 'children': []},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '154', 'type': 'subscript', 'children': ['155', '160']},{'id': '155', 'type': 'subscript', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '158', 'type': 'identifier', 'children': [], 'value': '_possibles'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '161', 'type': 'for_statement', 'children': ['162', '163', '171']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'range_'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '171', 'type': 'block', 'children': ['172', '178']},{'id': '172', 'type': 'if_statement', 'children': ['173', '176']},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '=='},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'continue_statement', 'children': []},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'subscript', 'children': ['187', '192']},{'id': '187', 'type': 'subscript', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '190', 'type': 'identifier', 'children': [], 'value': '_possibles'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '193', 'type': 'if_statement', 'children': ['194', '200']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '199'], 'value': '=='},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '199', 'type': 'integer', 'children': [], 'value': '1'},{'id': '200', 'type': 'block', 'children': ['201', '214', '236']},{'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': 'self'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'set_cell'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208', '209']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '221']},{'id': '216', 'type': 'attribute', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'solution_steps'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '225', 'type': 'identifier', 'children': [], 'value': '_format_step'},{'id': '226', 'type': 'argument_list', 'children': ['227', '228', '231']},{'id': '227', 'type': 'string', 'children': [], 'value': '"HIDDEN-COL"'},{'id': '228', 'type': 'tuple', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '231', 'type': 'subscript', 'children': ['232', '235']},{'id': '232', 'type': 'subscript', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '236', 'type': 'return_statement', 'children': ['237']},{'id': '237', 'type': 'True', 'children': []},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '241', 'type': 'subscript', 'children': ['242', '247']},{'id': '242', 'type': 'subscript', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': '_possibles'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '248', 'type': 'for_statement', 'children': ['249', '250', '261']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'range_'},{'id': '254', 'type': 'argument_list', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'box_i'},{'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '+'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'box_i'},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '261', 'type': 'block', 'children': ['262']},{'id': '262', 'type': 'for_statement', 'children': ['263', '264', '275']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'range_'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'box_j'},{'id': '270', 'type': 'binary_operator', 'children': ['271', '272'], 'value': '+'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'box_j'},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '275', 'type': 'block', 'children': ['276', '286']},{'id': '276', 'type': 'if_statement', 'children': ['277', '284']},{'id': '277', 'type': 'boolean_operator', 'children': ['278', '281'], 'value': 'and'},{'id': '278', 'type': 'comparison_operator', 'children': ['279', '280'], 'value': '=='},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '281', 'type': 'comparison_operator', 'children': ['282', '283'], 'value': '=='},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '284', 'type': 'block', 'children': ['285']},{'id': '285', 'type': 'continue_statement', 'children': []},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'subscript', 'children': ['295', '300']},{'id': '295', 'type': 'subscript', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '298', 'type': 'identifier', 'children': [], 'value': '_possibles'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '301', 'type': 'if_statement', 'children': ['302', '308']},{'id': '302', 'type': 'comparison_operator', 'children': ['303', '307'], 'value': '=='},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '307', 'type': 'integer', 'children': [], 'value': '1'},{'id': '308', 'type': 'block', 'children': ['309', '322', '344']},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'set_cell'},{'id': '314', 'type': 'argument_list', 'children': ['315', '316', '317']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '317', 'type': 'call', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '321', 'type': 'argument_list', 'children': []},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'call', 'children': ['324', '329']},{'id': '324', 'type': 'attribute', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'solution_steps'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '333', 'type': 'identifier', 'children': [], 'value': '_format_step'},{'id': '334', 'type': 'argument_list', 'children': ['335', '336', '339']},{'id': '335', 'type': 'string', 'children': [], 'value': '"HIDDEN-BOX"'},{'id': '336', 'type': 'tuple', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '339', 'type': 'subscript', 'children': ['340', '343']},{'id': '340', 'type': 'subscript', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '344', 'type': 'return_statement', 'children': ['345']},{'id': '345', 'type': 'True', 'children': []},{'id': '346', 'type': 'return_statement', 'children': ['347']},{'id': '347', 'type': 'False', 'children': []}
def _fill_hidden_singles(self): for i in utils.range_(self.side): box_i = (i // self.order) * self.order for j in utils.range_(self.side): box_j = (j // self.order) * self.order if self[i][j] > 0: continue p = self._possibles[i][j] for k in utils.range_(self.side): if k == j: continue p = p.difference(self._possibles[i][k]) if len(p) == 1: self.set_cell(i, j, p.pop()) self.solution_steps.append(self._format_step("HIDDEN-ROW", (i, j), self[i][j])) return True p = self._possibles[i][j] for k in utils.range_(self.side): if k == i: continue p = p.difference(self._possibles[k][j]) if len(p) == 1: self.set_cell(i, j, p.pop()) self.solution_steps.append(self._format_step("HIDDEN-COL", (i, j), self[i][j])) return True p = self._possibles[i][j] for k in utils.range_(box_i, box_i + self.order): for kk in utils.range_(box_j, box_j + self.order): if k == i and kk == j: continue p = p.difference(self._possibles[k][kk]) if len(p) == 1: self.set_cell(i, j, p.pop()) self.solution_steps.append(self._format_step("HIDDEN-BOX", (i, j), self[i][j])) return True return False
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '27', '35', '46']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '13', 'type': 'call', 'children': ['14', '23']},{'id': '14', 'type': 'attribute', 'children': ['15', '22']},{'id': '15', 'type': 'attribute', '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': 'model'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_meta'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'columns_sort'},{'id': '27', 'type': 'if_statement', 'children': ['28', '30']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '35', 'type': 'if_statement', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'return_statement', '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': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'field'}
def sort(self, request, reverse=False): field = self.model._meta.fields.get(self.columns_sort) if not field: return self.collection if reverse: field = field.desc() return self.collection.order_by(field)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_docstring'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'what'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '10', 'type': 'block', 'children': ['11', '20', '52', '60', '68', '80', '202', '209', '219', '234', '248', '338', '372', '376', '399', '405', '434']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'aliases'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '18', 'type': 'string', 'children': [], 'value': '"_sigaliases"'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'aliases'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '29']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '=='},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'what'},{'id': '28', 'type': 'string', 'children': [], 'value': '"module"'},{'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': 'aliases'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_aliases'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '45']},{'id': '37', 'type': 'attribute', 'children': ['38', '44']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'getsource'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_sigaliases'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'aliases'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sig_marker'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '59'], 'value': '+'},{'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '+'},{'id': '57', 'type': 'string', 'children': [], 'value': '":"'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'SIG_FIELD'},{'id': '59', 'type': 'string', 'children': [], 'value': '":"'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'is_class'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'in'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'what'},{'id': '65', 'type': 'tuple', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': '"class"'},{'id': '67', 'type': 'string', 'children': [], 'value': '"exception"'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'extract_signature'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '80', 'type': 'if_statement', 'children': ['81', '84']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'is'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '83', 'type': 'None', 'children': []},{'id': '84', 'type': 'block', 'children': ['85', '90', '98', '104', '116', '150', '156', '160', '190']},{'id': '85', 'type': 'if_statement', 'children': ['86', '88']},{'id': '86', 'type': 'not_operator', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'is_class'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'return_statement', 'children': []},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'init_method'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '97', 'type': 'string', 'children': [], 'value': '"__init__"'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'init_doc'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'init_method'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'init_lines'},{'id': '107', 'type': 'subscript', 'children': ['108', '113']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'init_doc'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '112', 'type': 'argument_list', 'children': []},{'id': '113', 'type': 'slice', 'children': ['114', '115']},{'id': '114', 'type': 'integer', 'children': [], 'value': '1'},{'id': '115', 'type': 'colon', 'children': []},{'id': '116', 'type': 'if_statement', 'children': ['117', '123']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '122'], 'value': '>'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'init_lines'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': 'block', 'children': ['124', '142']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'init_doc'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'textwrap'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'dedent'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'init_lines'},{'id': '139', 'type': 'slice', 'children': ['140', '141']},{'id': '140', 'type': 'integer', 'children': [], 'value': '1'},{'id': '141', 'type': 'colon', 'children': []},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'init_lines'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'init_doc'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'if_statement', 'children': ['151', '154']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'not'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sig_marker'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'init_doc'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'return_statement', 'children': []},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'sig_started'},{'id': '159', 'type': 'False', 'children': []},{'id': '160', 'type': 'for_statement', 'children': ['161', '162', '163']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'init_lines'},{'id': '163', 'type': 'block', 'children': ['164', '180']},{'id': '164', 'type': 'if_statement', 'children': ['165', '175']},{'id': '165', 'type': 'call', 'children': ['166', '173']},{'id': '166', 'type': 'attribute', 'children': ['167', '172']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '171', 'type': 'argument_list', 'children': []},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'sig_marker'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'sig_started'},{'id': '179', 'type': 'True', 'children': []},{'id': '180', 'type': 'if_statement', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'sig_started'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'extract_signature'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '202', 'type': 'if_statement', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'is_class'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'init_method'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '215']},{'id': '211', 'type': 'pattern_list', 'children': ['212', '213', '214']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'param_types'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'rtype'},{'id': '214', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'parse_signature'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'param_names'},{'id': '222', 'type': 'list_comprehension', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '224', 'type': 'for_in_clause', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '226', 'type': 'attribute', 'children': ['227', '233']},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '234', 'type': 'if_statement', 'children': ['235', '243']},{'id': '235', 'type': 'boolean_operator', 'children': ['236', '237'], 'value': 'and'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'is_class'},{'id': '237', 'type': '()', 'children': ['238']},{'id': '238', 'type': 'comparison_operator', 'children': ['239', '242'], 'value': '=='},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'param_names'},{'id': '241', 'type': 'integer', 'children': [], 'value': '0'},{'id': '242', 'type': 'string', 'children': [], 'value': '"self"'},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'delete_statement', 'children': ['245']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'param_names'},{'id': '247', 'type': 'integer', 'children': [], 'value': '0'},{'id': '248', 'type': 'if_statement', 'children': ['249', '258']},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '254'], 'value': '=='},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'param_names'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'param_types'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'for_statement', 'children': ['260', '263', '268']},{'id': '260', 'type': 'pattern_list', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '265', 'type': 'argument_list', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'param_names'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'param_types'},{'id': '268', 'type': 'block', 'children': ['269', '278', '287', '304']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '272', 'type': 'binary_operator', 'children': ['273', '274'], 'value': '%'},{'id': '273', 'type': 'string', 'children': [], 'value': '":param %(name)s:"'},{'id': '274', 'type': 'dictionary', 'children': ['275']},{'id': '275', 'type': 'pair', 'children': ['276', '277']},{'id': '276', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'aliases'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '287', 'type': 'if_statement', 'children': ['288', '291']},{'id': '288', 'type': 'comparison_operator', 'children': ['289', '290'], 'value': 'is'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '290', 'type': 'None', 'children': []},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '295', 'type': 'binary_operator', 'children': ['296', '297'], 'value': '%'},{'id': '296', 'type': 'string', 'children': [], 'value': '"*%(type)s* :sup:`%(alias)s`"'},{'id': '297', 'type': 'dictionary', 'children': ['298', '301']},{'id': '298', 'type': 'pair', 'children': ['299', '300']},{'id': '299', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '301', 'type': 'pair', 'children': ['302', '303']},{'id': '302', 'type': 'string', 'children': [], 'value': '"alias"'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '304', 'type': 'for_statement', 'children': ['305', '308', '312']},{'id': '305', 'type': 'pattern_list', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '308', 'type': 'call', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '312', 'type': 'block', 'children': ['313']},{'id': '313', 'type': 'if_statement', 'children': ['314', '320']},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '320', 'type': 'block', 'children': ['321', '337']},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '326', 'type': 'argument_list', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '328', 'type': 'binary_operator', 'children': ['329', '330'], 'value': '%'},{'id': '329', 'type': 'string', 'children': [], 'value': '":type %(name)s: %(type)s"'},{'id': '330', 'type': 'dictionary', 'children': ['331', '334']},{'id': '331', 'type': 'pair', 'children': ['332', '333']},{'id': '332', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '334', 'type': 'pair', 'children': ['335', '336']},{'id': '335', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '337', 'type': 'break_statement', 'children': []},{'id': '338', 'type': 'if_statement', 'children': ['339', '341']},{'id': '339', 'type': 'not_operator', 'children': ['340']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'is_class'},{'id': '341', 'type': 'block', 'children': ['342']},{'id': '342', 'type': 'for_statement', 'children': ['343', '346', '350']},{'id': '343', 'type': 'pattern_list', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '346', 'type': 'call', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '350', 'type': 'block', 'children': ['351']},{'id': '351', 'type': 'if_statement', 'children': ['352', '360']},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': 'tuple', 'children': ['358', '359']},{'id': '358', 'type': 'string', 'children': [], 'value': '":return:"'},{'id': '359', 'type': 'string', 'children': [], 'value': '":returns:"'},{'id': '360', 'type': 'block', 'children': ['361', '371']},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'call', 'children': ['363', '366']},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '366', 'type': 'argument_list', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '368', 'type': 'binary_operator', 'children': ['369', '370'], 'value': '+'},{'id': '369', 'type': 'string', 'children': [], 'value': '":rtype: "'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'rtype'},{'id': '371', 'type': 'break_statement', 'children': []},{'id': '372', 'type': 'expression_statement', 'children': ['373']},{'id': '373', 'type': 'assignment', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'sig_start'},{'id': '375', 'type': 'integer', 'children': [], 'value': '0'},{'id': '376', 'type': 'while_statement', 'children': ['377', '383']},{'id': '377', 'type': 'comparison_operator', 'children': ['378', '379'], 'value': '<'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'sig_start'},{'id': '379', 'type': 'call', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '381', 'type': 'argument_list', 'children': ['382']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '383', 'type': 'block', 'children': ['384', '395']},{'id': '384', 'type': 'if_statement', 'children': ['385', '393']},{'id': '385', 'type': 'call', 'children': ['386', '391']},{'id': '386', 'type': 'attribute', 'children': ['387', '390']},{'id': '387', 'type': 'subscript', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'sig_start'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '391', 'type': 'argument_list', 'children': ['392']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'sig_marker'},{'id': '393', 'type': 'block', 'children': ['394']},{'id': '394', 'type': 'break_statement', 'children': []},{'id': '395', 'type': 'expression_statement', 'children': ['396']},{'id': '396', 'type': 'augmented_assignment', 'children': ['397', '398'], 'value': '+='},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'sig_start'},{'id': '398', 'type': 'integer', 'children': [], 'value': '1'},{'id': '399', 'type': 'expression_statement', 'children': ['400']},{'id': '400', 'type': 'assignment', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'sig_end'},{'id': '402', 'type': 'binary_operator', 'children': ['403', '404'], 'value': '+'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'sig_start'},{'id': '404', 'type': 'integer', 'children': [], 'value': '1'},{'id': '405', 'type': 'while_statement', 'children': ['406', '412']},{'id': '406', 'type': 'comparison_operator', 'children': ['407', '408'], 'value': '<'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'sig_end'},{'id': '408', 'type': 'call', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '410', 'type': 'argument_list', 'children': ['411']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '412', 'type': 'block', 'children': ['413', '430']},{'id': '413', 'type': 'if_statement', 'children': ['414', '428']},{'id': '414', 'type': 'boolean_operator', 'children': ['415', '420'], 'value': 'or'},{'id': '415', 'type': '()', 'children': ['416']},{'id': '416', 'type': 'not_operator', 'children': ['417']},{'id': '417', 'type': 'subscript', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'sig_end'},{'id': '420', 'type': '()', 'children': ['421']},{'id': '421', 'type': 'comparison_operator', 'children': ['422', '427'], 'value': '!='},{'id': '422', 'type': 'subscript', 'children': ['423', '426']},{'id': '423', 'type': 'subscript', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'sig_end'},{'id': '426', 'type': 'integer', 'children': [], 'value': '0'},{'id': '427', 'type': 'string', 'children': [], 'value': '" "'},{'id': '428', 'type': 'block', 'children': ['429']},{'id': '429', 'type': 'break_statement', 'children': []},{'id': '430', 'type': 'expression_statement', 'children': ['431']},{'id': '431', 'type': 'augmented_assignment', 'children': ['432', '433'], 'value': '+='},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'sig_end'},{'id': '433', 'type': 'integer', 'children': [], 'value': '1'},{'id': '434', 'type': 'for_statement', 'children': ['435', '436', '444']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '436', 'type': 'call', 'children': ['437', '438']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '438', 'type': 'argument_list', 'children': ['439']},{'id': '439', 'type': 'call', 'children': ['440', '441']},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '441', 'type': 'argument_list', 'children': ['442', '443']},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'sig_start'},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'sig_end'},{'id': '444', 'type': 'block', 'children': ['445']},{'id': '445', 'type': 'delete_statement', 'children': ['446']},{'id': '446', 'type': 'subscript', 'children': ['447', '448']},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'i'}
def process_docstring(app, what, name, obj, options, lines): aliases = getattr(app, "_sigaliases", None) if aliases is None: if what == "module": aliases = get_aliases(inspect.getsource(obj).splitlines()) app._sigaliases = aliases sig_marker = ":" + SIG_FIELD + ":" is_class = what in ("class", "exception") signature = extract_signature("\n".join(lines)) if signature is None: if not is_class: return init_method = getattr(obj, "__init__") init_doc = init_method.__doc__ init_lines = init_doc.splitlines()[1:] if len(init_lines) > 1: init_doc = textwrap.dedent("\n".join(init_lines[1:])) init_lines = init_doc.splitlines() if sig_marker not in init_doc: return sig_started = False for line in init_lines: if line.lstrip().startswith(sig_marker): sig_started = True if sig_started: lines.append(line) signature = extract_signature("\n".join(lines)) if is_class: obj = init_method param_types, rtype, _ = parse_signature(signature) param_names = [p for p in inspect.signature(obj).parameters] if is_class and (param_names[0] == "self"): del param_names[0] if len(param_names) == len(param_types): for name, type_ in zip(param_names, param_types): find = ":param %(name)s:" % {"name": name} alias = aliases.get(type_) if alias is not None: type_ = "*%(type)s* :sup:`%(alias)s`" % {"type": type_, "alias": alias} for i, line in enumerate(lines): if line.startswith(find): lines.insert(i, ":type %(name)s: %(type)s" % {"name": name, "type": type_}) break if not is_class: for i, line in enumerate(lines): if line.startswith((":return:", ":returns:")): lines.insert(i, ":rtype: " + rtype) break sig_start = 0 while sig_start < len(lines): if lines[sig_start].startswith(sig_marker): break sig_start += 1 sig_end = sig_start + 1 while sig_end < len(lines): if (not lines[sig_end]) or (lines[sig_end][0] != " "): break sig_end += 1 for i in reversed(range(sig_start, sig_end)): del lines[i]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'main'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'block', 'children': ['8', '17', '32', '45', '68', '85', '101', '114', '125', '138', '161', '174', '202', '206', '314', '331']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ArgumentParser'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'prog'},{'id': '16', 'type': 'string', 'children': [], 'value': '"pygenstub"'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24', '27']},{'id': '23', 'type': 'string', 'children': [], 'value': '"--version"'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '26', 'type': 'string', 'children': [], 'value': '"version"'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '+'},{'id': '30', 'type': 'string', 'children': [], 'value': '"%(prog)s "'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '__version__'},{'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': 'parser'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '42']},{'id': '38', 'type': 'string', 'children': [], 'value': '"files"'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '41', 'type': 'string', 'children': [], 'value': '"*"'},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '44', 'type': 'string', 'children': [], 'value': '"generate stubs for given files"'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52', '53', '56', '59', '62', '65']},{'id': '51', 'type': 'string', 'children': [], 'value': '"-m"'},{'id': '52', 'type': 'string', 'children': [], 'value': '"--module"'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '55', 'type': 'string', 'children': [], 'value': '"append"'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'metavar'},{'id': '58', 'type': 'string', 'children': [], 'value': '"MODULE"'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '61', 'type': 'string', 'children': [], 'value': '"modules"'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '64', 'type': 'list', 'children': [], 'value': '[]'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '67', 'type': 'string', 'children': [], 'value': '"generate stubs for given modules"'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '76', '79', '82']},{'id': '74', 'type': 'string', 'children': [], 'value': '"-o"'},{'id': '75', 'type': 'string', 'children': [], 'value': '"--output"'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'metavar'},{'id': '78', 'type': 'string', 'children': [], 'value': '"PATH"'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '81', 'type': 'string', 'children': [], 'value': '"out_dir"'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '84', 'type': 'string', 'children': [], 'value': '"change the output directory"'},{'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': 'parser'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92', '95', '98']},{'id': '91', 'type': 'string', 'children': [], 'value': '"--generic"'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '94', 'type': 'string', 'children': [], 'value': '"store_true"'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '97', 'type': 'False', 'children': []},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '100', 'type': 'string', 'children': [], 'value': '"generate generic stubs"'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108', '111']},{'id': '107', 'type': 'string', 'children': [], 'value': '"--debug"'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '110', 'type': 'string', 'children': [], 'value': '"store_true"'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '113', 'type': 'string', 'children': [], 'value': '"enable debug messages"'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '117', 'type': 'conditional_expression', 'children': ['118', '119', '122'], 'value': 'if'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': 'is'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '121', 'type': 'None', 'children': []},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '135', 'type': 'slice', 'children': ['136', '137']},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'colon', 'children': []},{'id': '138', 'type': 'if_statement', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '142', 'type': 'block', 'children': ['143', '154']},{'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': 'logging'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'basicConfig'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'DEBUG'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'string', 'children': [], 'value': '"running in debug mode"'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '164', 'type': 'conditional_expression', 'children': ['165', '168', '173'], 'value': 'if'},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '172'], 'value': 'is'},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '172', 'type': 'None', 'children': []},{'id': '173', 'type': 'string', 'children': [], 'value': '""'},{'id': '174', 'type': 'if_statement', 'children': ['175', '189']},{'id': '175', 'type': 'boolean_operator', 'children': ['176', '180'], 'value': 'and'},{'id': '176', 'type': '()', 'children': ['177']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': '=='},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '179', 'type': 'string', 'children': [], 'value': '""'},{'id': '180', 'type': '()', 'children': ['181']},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '188'], 'value': '>'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '188', 'type': 'integer', 'children': [], 'value': '0'},{'id': '189', 'type': 'block', 'children': ['190', '195']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'string', 'children': [], 'value': '"Output directory must be given when generating stubs for modules."'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'integer', 'children': [], 'value': '1'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '205', 'type': 'list', 'children': [], 'value': '[]'},{'id': '206', 'type': 'for_statement', 'children': ['207', '208', '211']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '211', 'type': 'block', 'children': ['212', '238']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '215', 'type': 'conditional_expression', 'children': ['216', '225', '233'], 'value': 'if'},{'id': '216', 'type': 'call', 'children': ['217', '223']},{'id': '217', 'type': 'attribute', 'children': ['218', '222']},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'Path'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'string', 'children': [], 'value': '"**/*.py"'},{'id': '225', 'type': 'call', 'children': ['226', '232']},{'id': '226', 'type': 'attribute', 'children': ['227', '231']},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'Path'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'is_dir'},{'id': '232', 'type': 'argument_list', 'children': []},{'id': '233', 'type': 'list', 'children': ['234'], 'value': '[Path(path)]'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'Path'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '238', 'type': 'for_statement', 'children': ['239', '240', '241']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '241', 'type': 'block', 'children': ['242', '269', '292', '305']},{'id': '242', 'type': 'if_statement', 'children': ['243', '256']},{'id': '243', 'type': 'call', 'children': ['244', '250']},{'id': '244', 'type': 'attribute', 'children': ['245', '249']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'attribute', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'pardir'},{'id': '256', 'type': 'block', 'children': ['257']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '260', 'type': 'call', 'children': ['261', '268']},{'id': '261', 'type': 'attribute', 'children': ['262', '267']},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'absolute'},{'id': '266', 'type': 'argument_list', 'children': []},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'resolve'},{'id': '268', 'type': 'argument_list', 'children': []},{'id': '269', 'type': 'if_statement', 'children': ['270', '280']},{'id': '270', 'type': 'boolean_operator', 'children': ['271', '275'], 'value': 'and'},{'id': '271', 'type': '()', 'children': ['272']},{'id': '272', 'type': 'comparison_operator', 'children': ['273', '274'], 'value': '!='},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '274', 'type': 'string', 'children': [], 'value': '""'},{'id': '275', 'type': 'call', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'is_absolute'},{'id': '279', 'type': 'argument_list', 'children': []},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '284', 'type': 'call', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'relative_to'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '295', 'type': 'call', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'Path'},{'id': '297', 'type': 'argument_list', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'with_suffix'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'string', 'children': [], 'value': '".pyi"'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'tuple', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '314', 'type': 'for_statement', 'children': ['315', '316', '319']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'mod_name'},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '319', 'type': 'block', 'children': ['320']},{'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': 'modules'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '325', 'type': 'argument_list', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'get_pkg_paths'},{'id': '328', 'type': 'argument_list', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'mod_name'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'out_dir'},{'id': '331', 'type': 'for_statement', 'children': ['332', '335', '336']},{'id': '332', 'type': 'pattern_list', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '336', 'type': 'block', 'children': ['337', '346', '366', '399']},{'id': '337', 'type': 'expression_statement', 'children': ['338']},{'id': '338', 'type': 'call', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '342', 'type': 'argument_list', 'children': ['343', '344', '345']},{'id': '343', 'type': 'string', 'children': [], 'value': '"generating stub for %s to path %s"'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '346', 'type': 'with_statement', 'children': ['347', '357']},{'id': '347', 'type': 'with_clause', 'children': ['348']},{'id': '348', 'type': 'with_item', 'children': ['349']},{'id': '349', 'type': 'as_pattern', 'children': ['350', '355']},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '354', 'type': 'argument_list', 'children': []},{'id': '355', 'type': 'as_pattern_target', 'children': ['356']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '357', 'type': 'block', 'children': ['358']},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'assignment', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '361', 'type': 'call', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '365', 'type': 'argument_list', 'children': []},{'id': '366', 'type': 'try_statement', 'children': ['367', '380']},{'id': '367', 'type': 'block', 'children': ['368']},{'id': '368', 'type': 'expression_statement', 'children': ['369']},{'id': '369', 'type': 'assignment', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '371', 'type': 'call', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'get_stub'},{'id': '373', 'type': 'argument_list', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '375', 'type': 'keyword_argument', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'generic'},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'arguments'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'generic'},{'id': '380', 'type': 'except_clause', 'children': ['381', '385']},{'id': '381', 'type': 'as_pattern', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '383', 'type': 'as_pattern_target', 'children': ['384']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '385', 'type': 'block', 'children': ['386', '398']},{'id': '386', 'type': 'expression_statement', 'children': ['387']},{'id': '387', 'type': 'call', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '389', 'type': 'argument_list', 'children': ['390', '391', '392', '393']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '391', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '393', 'type': 'keyword_argument', 'children': ['394', '395']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '398', 'type': 'continue_statement', 'children': []},{'id': '399', 'type': 'if_statement', 'children': ['400', '403']},{'id': '400', 'type': 'comparison_operator', 'children': ['401', '402'], 'value': '!='},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '402', 'type': 'string', 'children': [], 'value': '""'},{'id': '403', 'type': 'block', 'children': ['404', '425']},{'id': '404', 'type': 'if_statement', 'children': ['405', '413']},{'id': '405', 'type': 'not_operator', 'children': ['406']},{'id': '406', 'type': 'call', 'children': ['407', '412']},{'id': '407', 'type': 'attribute', 'children': ['408', '411']},{'id': '408', 'type': 'attribute', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '412', 'type': 'argument_list', 'children': []},{'id': '413', 'type': 'block', 'children': ['414']},{'id': '414', 'type': 'expression_statement', 'children': ['415']},{'id': '415', 'type': 'call', 'children': ['416', '421']},{'id': '416', 'type': 'attribute', 'children': ['417', '420']},{'id': '417', 'type': 'attribute', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'mkdir'},{'id': '421', 'type': 'argument_list', 'children': ['422']},{'id': '422', 'type': 'keyword_argument', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '424', 'type': 'True', 'children': []},{'id': '425', 'type': 'with_statement', 'children': ['426', '437', '441']},{'id': '426', 'type': 'with_clause', 'children': ['427']},{'id': '427', 'type': 'with_item', 'children': ['428']},{'id': '428', 'type': 'as_pattern', 'children': ['429', '435']},{'id': '429', 'type': 'call', 'children': ['430', '433']},{'id': '430', 'type': 'attribute', 'children': ['431', '432']},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '433', 'type': 'argument_list', 'children': ['434']},{'id': '434', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '435', 'type': 'as_pattern_target', 'children': ['436']},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '437', 'type': 'ERROR', 'children': ['438']},{'id': '438', 'type': 'attribute', 'children': ['439', '440']},{'id': '439', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '441', 'type': 'block', 'children': [], 'value': ''}
def main(argv=None): parser = ArgumentParser(prog="pygenstub") parser.add_argument("--version", action="version", version="%(prog)s " + __version__) parser.add_argument("files", nargs="*", help="generate stubs for given files") parser.add_argument( "-m", "--module", action="append", metavar="MODULE", dest="modules", default=[], help="generate stubs for given modules", ) parser.add_argument( "-o", "--output", metavar="PATH", dest="out_dir", help="change the output directory" ) parser.add_argument( "--generic", action="store_true", default=False, help="generate generic stubs" ) parser.add_argument("--debug", action="store_true", help="enable debug messages") argv = argv if argv is not None else sys.argv arguments = parser.parse_args(argv[1:]) if arguments.debug: logging.basicConfig(level=logging.DEBUG) _logger.debug("running in debug mode") out_dir = arguments.out_dir if arguments.out_dir is not None else "" if (out_dir == "") and (len(arguments.modules) > 0): print("Output directory must be given when generating stubs for modules.") sys.exit(1) modules = [] for path in arguments.files: paths = Path(path).glob("**/*.py") if Path(path).is_dir() else [Path(path)] for source in paths: if str(source).startswith(os.path.pardir): source = source.absolute().resolve() if (out_dir != "") and source.is_absolute(): source = source.relative_to(source.root) destination = Path(out_dir, source.with_suffix(".pyi")) modules.append((source, destination)) for mod_name in arguments.modules: modules.extend(get_pkg_paths(mod_name, out_dir)) for source, destination in modules: _logger.info("generating stub for %s to path %s", source, destination) with source.open() as f: code = f.read() try: stub = get_stub(code, generic=arguments.generic) except Exception as e: print(source, "-", e, file=sys.stderr) continue if stub != "": if not destination.parent.exists(): destination.parent.mkdir(parents=True) with destination.open("w") as f: f.write("
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_code'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '38', '42', '81', '111', '117', '208']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '15']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'deco'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'decorators'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'if_statement', 'children': ['17', '28']},{'id': '17', 'type': 'boolean_operator', 'children': ['18', '22'], 'value': 'or'},{'id': '18', 'type': '()', 'children': ['19']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'in'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'deco'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'DECORATORS'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'deco'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': '".setter"'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '+'},{'id': '36', 'type': 'string', 'children': [], 'value': '"@"'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'deco'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '41', 'type': 'list', 'children': [], 'value': '[]'},{'id': '42', 'type': 'for_statement', 'children': ['43', '47', '50']},{'id': '43', 'type': 'pattern_list', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'has_default'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '50', 'type': 'block', 'children': ['51', '74']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'decl'},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '%'},{'id': '55', 'type': 'string', 'children': [], 'value': '"%(n)s%(t)s%(d)s"'},{'id': '56', 'type': 'dictionary', 'children': ['57', '60', '68']},{'id': '57', 'type': 'pair', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': '"n"'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '60', 'type': 'pair', 'children': ['61', '62']},{'id': '61', 'type': 'string', 'children': [], 'value': '"t"'},{'id': '62', 'type': 'conditional_expression', 'children': ['63', '66', '67'], 'value': 'if'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '+'},{'id': '64', 'type': 'string', 'children': [], 'value': '": "'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '67', 'type': 'string', 'children': [], 'value': '""'},{'id': '68', 'type': 'pair', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': '"d"'},{'id': '70', 'type': 'conditional_expression', 'children': ['71', '72', '73'], 'value': 'if'},{'id': '71', 'type': 'string', 'children': [], 'value': '" = ..."'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'has_default'},{'id': '73', 'type': 'string', 'children': [], 'value': '""'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'decl'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'slots'},{'id': '84', 'type': 'dictionary', 'children': ['85', '93', '98', '106']},{'id': '85', 'type': 'pair', 'children': ['86', '87']},{'id': '86', 'type': 'string', 'children': [], 'value': '"a"'},{'id': '87', 'type': 'conditional_expression', 'children': ['88', '89', '92'], 'value': 'if'},{'id': '88', 'type': 'string', 'children': [], 'value': '"async "'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': '_async'},{'id': '92', 'type': 'string', 'children': [], 'value': '""'},{'id': '93', 'type': 'pair', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': '"n"'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '98', 'type': 'pair', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': '"p"'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': '", "'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '106', 'type': 'pair', 'children': ['107', '108']},{'id': '107', 'type': 'string', 'children': [], 'value': '"r"'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'rtype'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'prototype'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '%'},{'id': '115', 'type': 'string', 'children': [], 'value': '"%(a)sdef %(n)s(%(p)s) -> %(r)s: ..."'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'slots'},{'id': '117', 'type': 'if_statement', 'children': ['118', '124', '132', '173']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '123'], 'value': '<='},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'prototype'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'LINE_LENGTH_LIMIT'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'prototype'},{'id': '132', 'type': 'elif_clause', 'children': ['133', '143']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '142'], 'value': '<='},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '+'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'INDENT'},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'slots'},{'id': '141', 'type': 'string', 'children': [], 'value': '"p"'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'LINE_LENGTH_LIMIT'},{'id': '143', 'type': 'block', 'children': ['144', '153', '164']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '%'},{'id': '151', 'type': 'string', 'children': [], 'value': '"%(a)sdef %(n)s("'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'slots'},{'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': 'stub'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '+'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'INDENT'},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'slots'},{'id': '163', 'type': 'string', 'children': [], 'value': '"p"'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'binary_operator', 'children': ['171', '172'], 'value': '%'},{'id': '171', 'type': 'string', 'children': [], 'value': '") -> %(r)s: ..."'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'slots'},{'id': '173', 'type': 'else_clause', 'children': ['174']},{'id': '174', 'type': 'block', 'children': ['175', '184', '199']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'binary_operator', 'children': ['182', '183'], 'value': '%'},{'id': '182', 'type': 'string', 'children': [], 'value': '"%(a)sdef %(n)s("'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'slots'},{'id': '184', 'type': 'for_statement', 'children': ['185', '186', '187']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '187', 'type': 'block', 'children': ['188']},{'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': 'stub'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'binary_operator', 'children': ['195', '198'], 'value': '+'},{'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '+'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'INDENT'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '198', 'type': 'string', 'children': [], 'value': '","'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '%'},{'id': '206', 'type': 'string', 'children': [], 'value': '") -> %(r)s: ..."'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'slots'},{'id': '208', 'type': 'return_statement', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'stub'}
def get_code(self): stub = [] for deco in self.decorators: if (deco in DECORATORS) or deco.endswith(".setter"): stub.append("@" + deco) parameters = [] for name, type_, has_default in self.parameters: decl = "%(n)s%(t)s%(d)s" % { "n": name, "t": ": " + type_ if type_ else "", "d": " = ..." if has_default else "", } parameters.append(decl) slots = { "a": "async " if self._async else "", "n": self.name, "p": ", ".join(parameters), "r": self.rtype, } prototype = "%(a)sdef %(n)s(%(p)s) -> %(r)s: ..." % slots if len(prototype) <= LINE_LENGTH_LIMIT: stub.append(prototype) elif len(INDENT + slots["p"]) <= LINE_LENGTH_LIMIT: stub.append("%(a)sdef %(n)s(" % slots) stub.append(INDENT + slots["p"]) stub.append(") -> %(r)s: ..." % slots) else: stub.append("%(a)sdef %(n)s(" % slots) for param in parameters: stub.append(INDENT + param + ",") stub.append(") -> %(r)s: ..." % slots) return stub
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'query_metric_stats'},{'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': 'metric_type'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'metric_id'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'bucketDuration'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'dictionary_splat_pattern', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'query_options'},{'id': '20', 'type': 'block', 'children': ['21', '51', '81', '111', '160']},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '33', '43']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '32'], 'value': 'is'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '39']},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'query_options'},{'id': '38', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'datetime_to_time_millis'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '43', 'type': 'else_clause', 'children': ['44']},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'query_options'},{'id': '49', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '51', 'type': 'if_statement', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'if_statement', 'children': ['57', '63', '73']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '62'], 'value': 'is'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'query_options'},{'id': '68', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'datetime_to_time_millis'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '80']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'query_options'},{'id': '79', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '81', 'type': 'if_statement', 'children': ['82', '85']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'bucketDuration'},{'id': '84', 'type': 'None', 'children': []},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'if_statement', 'children': ['87', '93', '103']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '92'], 'value': 'is'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'bucketDuration'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'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': 'query_options'},{'id': '98', 'type': 'string', 'children': [], 'value': "'bucketDuration'"},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'timedelta_to_duration'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'bucketDuration'},{'id': '103', 'type': 'else_clause', 'children': ['104']},{'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': 'query_options'},{'id': '109', 'type': 'string', 'children': [], 'value': "'bucketDuration'"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'bucketDuration'},{'id': '111', 'type': 'if_statement', 'children': ['112', '115', '131']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'is'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'metric_id'},{'id': '114', 'type': 'None', 'children': []},{'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': 'url'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_get_metrics_stats_url'},{'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': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_get_metrics_single_url'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'metric_type'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'metric_id'},{'id': '131', 'type': 'else_clause', 'children': ['132']},{'id': '132', 'type': 'block', 'children': ['133', '146']},{'id': '133', 'type': 'if_statement', 'children': ['134', '140']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '139'], 'value': '<'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'query_options'},{'id': '139', 'type': 'integer', 'children': [], 'value': '0'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'raise_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'HawkularError'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'string', 'children': [], 'value': "'Tags are required when querying without metric_id'"},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': '_get_metrics_stats_url'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_get_url'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'metric_type'},{'id': '160', 'type': 'return_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': '_get'},{'id': '165', 'type': 'argument_list', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '167', 'type': 'dictionary_splat', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'query_options'}
def query_metric_stats(self, metric_type, metric_id=None, start=None, end=None, bucketDuration=None, **query_options): if start is not None: if type(start) is datetime: query_options['start'] = datetime_to_time_millis(start) else: query_options['start'] = start if end is not None: if type(end) is datetime: query_options['end'] = datetime_to_time_millis(end) else: query_options['end'] = end if bucketDuration is not None: if type(bucketDuration) is timedelta: query_options['bucketDuration'] = timedelta_to_duration(bucketDuration) else: query_options['bucketDuration'] = bucketDuration if metric_id is not None: url = self._get_metrics_stats_url(self._get_metrics_single_url(metric_type, metric_id)) else: if len(query_options) < 0: raise HawkularError('Tags are required when querying without metric_id') url = self._get_metrics_stats_url(self._get_url(metric_type)) return self._get(url, **query_options)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_files'},{'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': 'path'},{'id': '6', 'type': 'string', 'children': [], 'value': "''"},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '9', 'type': 'string', 'children': [], 'value': "''"},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '21', 'type': 'True', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'block', 'children': ['26', '48']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'gen'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'generate_files'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33', '36', '39', '42', '45']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '48', 'type': 'if_statement', 'children': ['49', '58', '71', '81']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '51', 'type': 'argument_list', 'children': ['52', '55']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'Mapping'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'return_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '62', 'type': 'generator_expression', 'children': ['63', '68']},{'id': '63', 'type': 'tuple', 'children': ['64', '67']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ff'},{'id': '66', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ff'},{'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ff'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'gen'},{'id': '71', 'type': 'elif_clause', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '74', 'type': 'None', 'children': []},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'gen'},{'id': '81', 'type': 'else_clause', 'children': ['82']},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'gen'}
def find_files(path='', ext='', level=None, typ=list, dirs=False, files=True, verbosity=0): gen = generate_files(path, ext=ext, level=level, dirs=dirs, files=files, verbosity=verbosity) if isinstance(typ(), collections.Mapping): return typ((ff['path'], ff) for ff in gen) elif typ is not None: return typ(gen) else: return gen
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'limitted_dump'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '12', 'type': 'string', 'children': [], 'value': "'tweets.json'"},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '15', 'type': 'integer', 'children': [], 'value': '450'},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'rate'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'TWITTER_SEARCH_RATE_LIMIT'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '21', 'type': 'unary_operator', 'children': ['22'], 'value': '-'},{'id': '22', 'type': 'integer', 'children': [], 'value': '1'},{'id': '23', 'type': 'block', 'children': ['24', '34', '40', '57', '66', '75']},{'id': '24', 'type': 'if_statement', 'children': ['25', '27']},{'id': '25', 'type': 'not_operator', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_twitter'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '39'], 'value': 'or'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '39', 'type': 'string', 'children': [], 'value': "'python'"},{'id': '40', 'type': 'if_statement', 'children': ['41', '46']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'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': 'cursor'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_cursor'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'newline'},{'id': '60', 'type': 'conditional_expression', 'children': ['61', '62', '65'], 'value': 'if'},{'id': '61', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'string', 'children': [], 'value': "''"},{'id': '66', 'type': 'if_statement', 'children': ['67', '70']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '<'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'indent'},{'id': '74', 'type': 'None', 'children': []},{'id': '75', 'type': 'with_statement', 'children': ['76', '95']},{'id': '76', 'type': 'with_clause', 'children': ['77']},{'id': '77', 'type': 'with_item', 'children': ['78']},{'id': '78', 'type': 'as_pattern', 'children': ['79', '93']},{'id': '79', 'type': '()', 'children': ['80']},{'id': '80', 'type': 'conditional_expression', 'children': ['81', '86', '92'], 'value': 'if'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '85', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '86', 'type': 'not_operator', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '93', 'type': 'as_pattern_target', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '95', 'type': 'block', 'children': ['96', '103', '179']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'string', 'children': [], 'value': "'[\\n'"},{'id': '103', 'type': 'for_statement', 'children': ['104', '107', '111']},{'id': '104', 'type': 'pattern_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '111', 'type': 'block', 'children': ['112', '127', '146', '158']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '127', 'type': 'if_statement', 'children': ['128', '133', '143']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '<'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '-'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '+'},{'id': '141', 'type': 'string', 'children': [], 'value': "','"},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'newline'},{'id': '143', 'type': 'else_clause', 'children': ['144']},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'break_statement', 'children': []},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'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': 'twitter'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'get_lastfunction_header'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'string', 'children': [], 'value': "'x-rate-limit-remaining'"},{'id': '158', 'type': 'if_statement', 'children': ['159', '162', '170']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': '>'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '161', 'type': 'integer', 'children': [], 'value': '0'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'binary_operator', 'children': ['168', '169'], 'value': '/'},{'id': '168', 'type': 'float', 'children': [], 'value': '1.'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'rate'},{'id': '170', 'type': 'else_clause', 'children': ['171']},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '*'},{'id': '177', 'type': 'integer', 'children': [], 'value': '15'},{'id': '178', 'type': 'integer', 'children': [], 'value': '60'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'string', 'children': [], 'value': "'\\n]\\n'"}
def limitted_dump(cursor=None, twitter=None, path='tweets.json', limit=450, rate=TWITTER_SEARCH_RATE_LIMIT, indent=-1): if not twitter: twitter = get_twitter() cursor = cursor or 'python' if isinstance(cursor, basestring): cursor = get_cursor(twitter, search=cursor) newline = '\n' if indent is not None else '' if indent < 0: indent = None with (open(path, 'w') if not isinstance(path, file) else path) as f: f.write('[\n') for i, obj in enumerate(cursor): f.write(json.dumps(obj, indent=indent)) if i < limit - 1: f.write(',' + newline) else: break remaining = int(twitter.get_lastfunction_header('x-rate-limit-remaining')) if remaining > 0: sleep(1. / rate) else: sleep(15 * 60) f.write('\n]\n')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '13', 'type': 'argument_list', 'children': ['14', '17', '30']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '19', 'type': 'lambda', 'children': ['20', '22']},{'id': '20', 'type': 'lambda_parameters', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26', '29']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'columns_sort'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'reverse'}
async def sort(self, request, reverse=False): return sorted( self.collection, key=lambda o: getattr(o, self.columns_sort, 0), reverse=reverse)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_request'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'key_is_cik'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'extra_headers'},{'id': '12', 'type': 'dictionary', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '55', '59', '76', '87', '93', '100', '116', '124', '139']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18', '45']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': '=='},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '17', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '18', 'type': 'block', 'children': ['19', '41']},{'id': '19', 'type': 'if_statement', 'children': ['20', '26', '35']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '>'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'url'},{'id': '30', 'type': 'binary_operator', 'children': ['31', '34'], 'value': '+'},{'id': '31', 'type': 'binary_operator', 'children': ['32', '33'], 'value': '+'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '33', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '35', 'type': 'else_clause', 'children': ['36']},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'else_clause', 'children': ['46']},{'id': '46', 'type': 'block', 'children': ['47', '51']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '58', 'type': 'dictionary', 'children': []},{'id': '59', 'type': 'if_statement', 'children': ['60', '61', '68']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'key_is_cik'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '67']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '66', 'type': 'string', 'children': [], 'value': "'X-Exosite-CIK'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '75']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '74', 'type': 'string', 'children': [], 'value': "'X-Exosite-Token'"},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '76', 'type': 'if_statement', 'children': ['77', '80']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': '=='},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '79', 'type': 'string', 'children': [], 'value': "'POST'"},{'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': 'headers'},{'id': '85', 'type': 'string', 'children': [], 'value': "'Content-Type'"},{'id': '86', 'type': 'string', 'children': [], 'value': "'application/x-www-form-urlencoded; charset=utf-8'"},{'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': 'headers'},{'id': '91', 'type': 'string', 'children': [], 'value': "'Accept'"},{'id': '92', 'type': 'string', 'children': [], 'value': "'text/plain, text/csv, application/x-www-form-urlencoded'"},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'extra_headers'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'pattern_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '105', 'type': 'call', 'children': ['106', '111']},{'id': '106', 'type': 'attribute', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_onephttp'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113', '114', '115']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'pr'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ProvisionResponse'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '124', 'type': 'if_statement', 'children': ['125', '133']},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '129'], 'value': 'and'},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': '_raise_api_exceptions'},{'id': '129', 'type': 'not_operator', 'children': ['130']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'pr'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'isok'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'raise_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'ProvisionException'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'pr'},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'pr'}
def _request(self, path, key, data, method, key_is_cik, extra_headers={}): if method == 'GET': if len(data) > 0: url = path + '?' + data else: url = path body = None else: url = path body = data headers = {} if key_is_cik: headers['X-Exosite-CIK'] = key else: headers['X-Exosite-Token'] = key if method == 'POST': headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8' headers['Accept'] = 'text/plain, text/csv, application/x-www-form-urlencoded' headers.update(extra_headers) body, response = self._onephttp.request(method, url, body, headers) pr = ProvisionResponse(body, response) if self._raise_api_exceptions and not pr.isok: raise ProvisionException(pr) return pr
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_intervals'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'as_context'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '57', '79', '88', '94', '103']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '12']},{'id': '10', 'type': 'function_name', 'children': [], 'value': '_regions_from_range'},{'id': '11', 'type': 'parameters', 'children': []},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'if_statement', 'children': ['14', '15', '47']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'as_context'},{'id': '15', 'type': 'block', 'children': ['16', '37']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ctxs'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'subscript', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'pf'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '29', 'type': 'slice', 'children': ['30', '33', '34']},{'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '-'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'colon', 'children': []},{'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '-'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '36', 'type': 'integer', 'children': [], 'value': '1'},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'list_comprehension', 'children': ['39', '44']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ContextInterval'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '44', 'type': 'for_in_clause', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ctxs'},{'id': '47', 'type': 'else_clause', 'children': ['48']},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'list', 'children': ['51'], 'value': '[LineInterval(filename, start, stop)]'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'LineInterval'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55', '56']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '57', 'type': 'if_statement', 'children': ['58', '61', '73']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'in'},{'id': '59', 'type': 'string', 'children': [], 'value': "':'"},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '67']},{'id': '64', 'type': 'pattern_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'subpath'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'string', 'children': [], 'value': "':'"},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'subpath'},{'id': '78', 'type': 'string', 'children': [], 'value': "''"},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'pf'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'PythonFile'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'from_modulename'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'pf'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'rng'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'NUMBER_RE'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'subpath'},{'id': '103', 'type': 'if_statement', 'children': ['104', '105', '133', '165']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'rng'},{'id': '105', 'type': 'block', 'children': ['106', '121', '129']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '111']},{'id': '108', 'type': 'pattern_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'rng'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'integer', 'children': [], 'value': '0'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '124', 'type': 'boolean_operator', 'children': ['125', '126'], 'value': 'or'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'return_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_regions_from_range'},{'id': '132', 'type': 'argument_list', 'children': []},{'id': '133', 'type': 'elif_clause', 'children': ['134', '136']},{'id': '134', 'type': 'not_operator', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'subpath'},{'id': '136', 'type': 'block', 'children': ['137', '149', '161']},{'id': '137', 'type': 'if_statement', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'as_context'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'return_statement', 'children': ['141']},{'id': '141', 'type': 'list', 'children': ['142'], 'value': '[ContextInterval(filename, pf.prefix)]'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'ContextInterval'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'pf'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '154']},{'id': '151', 'type': 'pattern_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '154', 'type': 'expression_list', 'children': ['155', '156']},{'id': '155', 'type': 'integer', 'children': [], 'value': '1'},{'id': '156', 'type': 'binary_operator', 'children': ['157', '160'], 'value': '+'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'pf'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'line_count'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'return_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': '_regions_from_range'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'else_clause', 'children': ['166']},{'id': '166', 'type': 'block', 'children': ['167', '177', '195']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '170', 'type': 'binary_operator', 'children': ['171', '176'], 'value': '+'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '175'], 'value': '+'},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'pf'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '175', 'type': 'string', 'children': [], 'value': "':'"},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'subpath'},{'id': '177', 'type': 'if_statement', 'children': ['178', '183']},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': 'not'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'pf'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'raise_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '%'},{'id': '189', 'type': 'string', 'children': [], 'value': '"%s is not a valid context for %s"'},{'id': '190', 'type': 'tuple', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'pf'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '195', 'type': 'if_statement', 'children': ['196', '197', '205']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'as_context'},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'return_statement', 'children': ['199']},{'id': '199', 'type': 'list', 'children': ['200'], 'value': '[ContextInterval(filename, context)]'},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'ContextInterval'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '205', 'type': 'else_clause', 'children': ['206']},{'id': '206', 'type': 'block', 'children': ['207', '218']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '212']},{'id': '209', 'type': 'pattern_list', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'pf'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'context_range'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '218', 'type': 'return_statement', 'children': ['219']},{'id': '219', 'type': 'list', 'children': ['220'], 'value': '[LineInterval(filename, start, stop)]'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'LineInterval'},{'id': '222', 'type': 'argument_list', 'children': ['223', '224', '225']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'stop'}
def parse_intervals(path, as_context=False): def _regions_from_range(): if as_context: ctxs = list(set(pf.lines[start - 1: stop - 1])) return [ ContextInterval(filename, ctx) for ctx in ctxs ] else: return [LineInterval(filename, start, stop)] if ':' in path: path, subpath = path.split(':') else: subpath = '' pf = PythonFile.from_modulename(path) filename = pf.filename rng = NUMBER_RE.match(subpath) if rng: start, stop = map(int, rng.groups(0)) stop = stop or start + 1 return _regions_from_range() elif not subpath: if as_context: return [ContextInterval(filename, pf.prefix)] start, stop = 1, pf.line_count + 1 return _regions_from_range() else: context = pf.prefix + ':' + subpath if context not in pf.lines: raise ValueError("%s is not a valid context for %s" % (context, pf.prefix)) if as_context: return [ContextInterval(filename, context)] else: start, stop = pf.context_range(context) return [LineInterval(filename, start, stop)]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'graphiter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ascendants'},{'id': '9', 'type': 'integer', 'children': [], 'value': '0'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'descendants'},{'id': '12', 'type': 'integer', 'children': [], 'value': '1'},{'id': '13', 'type': 'block', 'children': ['14', '20', '29', '35', '44', '51', '137']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '+'},{'id': '18', 'type': 'integer', 'children': [], 'value': '0'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ascendants'},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': '!='},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'augmented_assignment', 'children': ['27', '28'], 'value': '-='},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '+'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'descendants'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '!='},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'augmented_assignment', 'children': ['42', '43'], 'value': '-='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '43', 'type': 'integer', 'children': [], 'value': '1'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '51', 'type': 'if_statement', 'children': ['52', '63']},{'id': '52', 'type': 'boolean_operator', 'children': ['53', '56'], 'value': 'and'},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '!='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'descendants'},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '62'], 'value': 'is'},{'id': '57', 'type': 'subscript', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'downwards'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '62', 'type': 'True', 'children': []},{'id': '63', 'type': 'block', 'children': ['64', '72']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '71']},{'id': '66', 'type': 'subscript', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'downwards'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '71', 'type': 'False', 'children': []},{'id': '72', 'type': 'for_statement', 'children': ['73', '76', '82']},{'id': '73', 'type': 'pattern_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'obj'},{'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': 'predicate_objects'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '82', 'type': 'block', 'children': ['83', '95', '105']},{'id': '83', 'type': 'if_statement', 'children': ['84', '93']},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '88'], 'value': 'and'},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': '=='},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'BNode'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'continue_statement', 'children': []},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'tuple', 'children': ['102', '103', '104']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '105', 'type': 'if_statement', 'children': ['106', '120']},{'id': '106', 'type': 'boolean_operator', 'children': ['107', '110'], 'value': 'and'},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': '!='},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '109', 'type': 'integer', 'children': [], 'value': '0'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '119'], 'value': 'is'},{'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': 'downwards'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '119', 'type': 'True', 'children': []},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'graphiter'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128', '131', '134']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ascendants'},{'id': '133', 'type': 'integer', 'children': [], 'value': '0'},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'descendants'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '137', 'type': 'if_statement', 'children': ['138', '149']},{'id': '138', 'type': 'boolean_operator', 'children': ['139', '142'], 'value': 'and'},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '!='},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ascendants'},{'id': '141', 'type': 'integer', 'children': [], 'value': '0'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '148'], 'value': 'is'},{'id': '143', 'type': 'subscript', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'updwards'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '148', 'type': 'True', 'children': []},{'id': '149', 'type': 'block', 'children': ['150', '158']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '157']},{'id': '152', 'type': 'subscript', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'updwards'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '157', 'type': 'False', 'children': []},{'id': '158', 'type': 'for_statement', 'children': ['159', '162', '170']},{'id': '159', 'type': 'pattern_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'subject_predicates'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '170', 'type': 'block', 'children': ['171', '183', '193']},{'id': '171', 'type': 'if_statement', 'children': ['172', '181']},{'id': '172', 'type': 'boolean_operator', 'children': ['173', '176'], 'value': 'and'},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '=='},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '175', 'type': 'integer', 'children': [], 'value': '0'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'BNode'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'continue_statement', 'children': []},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'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': 'add'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'tuple', 'children': ['190', '191', '192']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '193', 'type': 'if_statement', 'children': ['194', '208']},{'id': '194', 'type': 'boolean_operator', 'children': ['195', '198'], 'value': 'and'},{'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': '!='},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '197', 'type': 'integer', 'children': [], 'value': '0'},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '207'], 'value': 'is'},{'id': '199', 'type': 'subscript', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'updwards'},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '207', 'type': 'True', 'children': []},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'graphiter'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216', '219', '222']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'ascendants'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'descendants'},{'id': '224', 'type': 'integer', 'children': [], 'value': '0'}
def graphiter(self, graph, target, ascendants=0, descendants=1): asc = 0 + ascendants if asc != 0: asc -= 1 desc = 0 + descendants if desc != 0: desc -= 1 t = str(target) if descendants != 0 and self.downwards[t] is True: self.downwards[t] = False for pred, obj in graph.predicate_objects(target): if desc == 0 and isinstance(obj, BNode): continue self.add((target, pred, obj)) if desc != 0 and self.downwards[str(obj)] is True: self.graphiter(graph, target=obj, ascendants=0, descendants=desc) if ascendants != 0 and self.updwards[t] is True: self.updwards[t] = False for s, p in graph.subject_predicates(object=target): if desc == 0 and isinstance(s, BNode): continue self.add((s, p, target)) if asc != 0 and self.updwards[str(s)] is True: self.graphiter(graph, target=s, ascendants=asc, descendants=0)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_aliases_to_device_objects'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '45']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'all_devices'},{'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_all_devices_in_portal'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '17']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'dev_o'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'all_devices'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dev_o'},{'id': '22', 'type': 'string', 'children': [], 'value': "'portals_aliases'"},{'id': '23', 'type': 'subscript', 'children': ['24', '42']},{'id': '24', 'type': 'subscript', 'children': ['25', '41']},{'id': '25', 'type': 'subscript', 'children': ['26', '40']},{'id': '26', 'type': 'subscript', 'children': ['27', '39']},{'id': '27', 'type': 'subscript', 'children': ['28', '38']},{'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_portal_by_name'},{'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': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'portal_name'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'integer', 'children': [], 'value': '2'},{'id': '39', 'type': 'integer', 'children': [], 'value': '1'},{'id': '40', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '41', 'type': 'string', 'children': [], 'value': "'aliases'"},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dev_o'},{'id': '44', 'type': 'string', 'children': [], 'value': "'rid'"},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'all_devices'}
def map_aliases_to_device_objects(self): all_devices = self.get_all_devices_in_portal() for dev_o in all_devices: dev_o['portals_aliases'] = self.get_portal_by_name( self.portal_name() )[2][1]['info']['aliases'][ dev_o['rid'] ] return all_devices
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_sorted_device_list'},{'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': 'device_list'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '10', 'type': 'string', 'children': [], 'value': "'sn'"},{'id': '11', 'type': 'block', 'children': ['12', '25', '29', '206']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'dev_list'},{'id': '15', 'type': 'conditional_expression', 'children': ['16', '17', '20'], 'value': 'if'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'device_list'},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'device_list'},{'id': '19', 'type': 'None', 'children': []},{'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': 'get_all_devices_in_portal'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted_dev_list'},{'id': '28', 'type': 'list', 'children': [], 'value': '[]'},{'id': '29', 'type': 'if_statement', 'children': ['30', '33', '78', '141', '190']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '=='},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '32', 'type': 'string', 'children': [], 'value': "'sn'"},{'id': '33', 'type': 'block', 'children': ['34', '50', '57']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '37', 'type': 'list_comprehension', 'children': ['38', '41', '44']},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dev_list'},{'id': '44', 'type': 'if_clause', 'children': ['45']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': 'is'},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '49', 'type': 'None', 'children': []},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sorted_dev_list'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'list_comprehension', 'children': ['68', '69', '72']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '69', 'type': 'for_in_clause', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dev_list'},{'id': '72', 'type': 'if_clause', 'children': ['73']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '77'], 'value': '=='},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '76', 'type': 'string', 'children': [], 'value': "'sn'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'elif_clause', 'children': ['79', '82']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '=='},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '81', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '82', 'type': 'block', 'children': ['83', '108', '115']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '86', 'type': 'list_comprehension', 'children': ['87', '94', '95', '98']},{'id': '87', 'type': 'subscript', 'children': ['88', '93']},{'id': '88', 'type': 'subscript', 'children': ['89', '92']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '91', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '92', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '94', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'dev_list'},{'id': '98', 'type': 'if_clause', 'children': ['99']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '107'], 'value': 'is'},{'id': '100', 'type': 'subscript', 'children': ['101', '106']},{'id': '101', 'type': 'subscript', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '104', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '105', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '107', 'type': 'None', 'children': []},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '115', 'type': 'for_statement', 'children': ['116', '117', '118']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'sorted_dev_list'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'list_comprehension', 'children': ['126', '127', '130', '131']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '127', 'type': 'for_in_clause', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'dev_list'},{'id': '130', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '131', 'type': 'if_clause', 'children': ['132']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '140'], 'value': '=='},{'id': '133', 'type': 'subscript', 'children': ['134', '139']},{'id': '134', 'type': 'subscript', 'children': ['135', '138']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '137', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '138', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '141', 'type': 'elif_clause', 'children': ['142', '145']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '=='},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '144', 'type': 'string', 'children': [], 'value': "'portals_aliases'"},{'id': '145', 'type': 'block', 'children': ['146', '162', '169']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '149', 'type': 'list_comprehension', 'children': ['150', '153', '156']},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '153', 'type': 'for_in_clause', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'dev_list'},{'id': '156', 'type': 'if_clause', 'children': ['157']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '161'], 'value': 'is'},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '161', 'type': 'None', 'children': []},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '172']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '172', 'type': 'block', 'children': ['173']},{'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': 'sorted_dev_list'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'list_comprehension', 'children': ['180', '181', '184']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '181', 'type': 'for_in_clause', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'dev_list'},{'id': '184', 'type': 'if_clause', 'children': ['185']},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '189'], 'value': '=='},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '190', 'type': 'else_clause', 'children': ['191']},{'id': '191', 'type': 'block', 'children': ['192', '202']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'string', 'children': [], 'value': '"Sort key {!r} not recognized."'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '205', 'type': 'None', 'children': []},{'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': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'print_device_list'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'device_list'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'sorted_dev_list'}
def print_sorted_device_list(self, device_list=None, sort_key='sn'): dev_list = device_list if device_list is not None else self.get_all_devices_in_portal() sorted_dev_list = [] if sort_key == 'sn': sort_keys = [ k[sort_key] for k in dev_list if k[sort_key] is not None ] sort_keys = sorted(sort_keys) for key in sort_keys: sorted_dev_list.extend([ d for d in dev_list if d['sn'] == key ]) elif sort_key == 'name': sort_keys = [ k['info']['description'][sort_key]\ for k in dev_list if k['info']['description'][sort_key] is not None ] sort_keys = sorted(sort_keys) for key in sort_keys: sorted_dev_list.extend( [ d for d in dev_list\ if d['info']['description'][sort_key] == key ] ) elif sort_key == 'portals_aliases': sort_keys = [ k[sort_key] for k in dev_list if k[sort_key] is not None ] sort_keys = sorted(sort_keys) for key in sort_keys: sorted_dev_list.extend([ d for d in dev_list if d[sort_key] == key ]) else: print("Sort key {!r} not recognized.".format(sort_key)) sort_keys = None self.print_device_list(device_list=sorted_dev_list)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'enrich'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '6', 'type': 'block', 'children': ['7', '24', '37', '41', '49', '148', '164']},{'id': '7', 'type': 'for_statement', 'children': ['8', '9', '10']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'if_statement', 'children': ['12', '19']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'not'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'first_column'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'subscript', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'append_df'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'for_statement', 'children': ['50', '51', '52']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'cell'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'first_column'},{'id': '52', 'type': 'block', 'children': ['53', '142']},{'id': '53', 'type': 'if_statement', 'children': ['54', '60']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '59'], 'value': '>='},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'cell'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'block', 'children': ['61', '69', '86', '107', '122', '134']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'for_statement', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '78']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '78', 'type': 'subscript', 'children': ['79', '84', '85']},{'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': 'data'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'extra_df'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'binary_operator', 'children': ['95', '103'], 'value': '*'},{'id': '95', 'type': 'list', 'children': ['96'], 'value': '[self.data.loc[count]]'},{'id': '96', 'type': 'subscript', 'children': ['97', '102']},{'id': '97', 'type': 'attribute', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'extra_df'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'append_df'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'append_df'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'extra_df'},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ignore_index'},{'id': '133', 'type': 'True', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'extra_df'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '+'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '147', 'type': 'integer', 'children': [], 'value': '1'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'data'},{'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': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'append_df'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'ignore_index'},{'id': '163', 'type': 'True', 'children': []},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'data'}
def enrich(self, columns): for column in columns: if column not in self.data.columns: return self.data first_column = list(self.data[columns[0]]) count = 0 append_df = pandas.DataFrame() for cell in first_column: if len(cell) >= 1: df = pandas.DataFrame() for column in columns: df[column] = self.data.loc[count, column] extra_df = pandas.DataFrame([self.data.loc[count]] * len(df)) for column in columns: extra_df[column] = list(df[column]) append_df = append_df.append(extra_df, ignore_index=True) extra_df = pandas.DataFrame() count = count + 1 self.data = self.data.append(append_df, ignore_index=True) return self.data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_metadata'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'xml'},{'id': '7', 'type': 'block', 'children': ['8', '45', '82', '99', '131']},{'id': '8', 'type': 'for_statement', 'children': ['9', '10', '19']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'xml'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': '"ti:description"'},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'XPATH_NAMESPACES'},{'id': '19', 'type': 'block', 'children': ['20', '29']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'lg'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': '"{http://www.w3.org/XML/1998/namespace}lang"'},{'id': '29', 'type': 'if_statement', 'children': ['30', '33']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'lg'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'set_cts_property'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41', '44']},{'id': '40', 'type': 'string', 'children': [], 'value': '"description"'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'lg'},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '56']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'xml'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': '"ti:label"'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'XPATH_NAMESPACES'},{'id': '56', 'type': 'block', 'children': ['57', '66']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'lg'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'string', 'children': [], 'value': '"{http://www.w3.org/XML/1998/namespace}lang"'},{'id': '66', 'type': 'if_statement', 'children': ['67', '70']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'lg'},{'id': '69', 'type': 'None', 'children': []},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'set_cts_property'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '81']},{'id': '77', 'type': 'string', 'children': [], 'value': '"label"'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'lg'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'citation'},{'id': '87', 'type': 'call', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'CLASS_CITATION'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ingest'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95', '98']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'xml'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'citation'},{'id': '98', 'type': 'string', 'children': [], 'value': '"ti:online/ti:citationMapping/ti:citation"'},{'id': '99', 'type': 'for_statement', 'children': ['100', '101', '110']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'xml'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'xpath'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107']},{'id': '106', 'type': 'string', 'children': [], 'value': '"ti:about"'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'XPATH_NAMESPACES'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'set_link'},{'id': '116', 'type': 'argument_list', 'children': ['117', '125']},{'id': '117', 'type': 'call', 'children': ['118', '123']},{'id': '118', 'type': 'attribute', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'RDF_NAMESPACES'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'CTS'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'string', 'children': [], 'value': '"about"'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'string', 'children': [], 'value': "'urn'"},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': '_parse_structured_metadata'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'xml'}
def parse_metadata(cls, obj, xml): for child in xml.xpath("ti:description", namespaces=XPATH_NAMESPACES): lg = child.get("{http://www.w3.org/XML/1998/namespace}lang") if lg is not None: obj.set_cts_property("description", child.text, lg) for child in xml.xpath("ti:label", namespaces=XPATH_NAMESPACES): lg = child.get("{http://www.w3.org/XML/1998/namespace}lang") if lg is not None: obj.set_cts_property("label", child.text, lg) obj.citation = cls.CLASS_CITATION.ingest(xml, obj.citation, "ti:online/ti:citationMapping/ti:citation") for child in xml.xpath("ti:about", namespaces=XPATH_NAMESPACES): obj.set_link(RDF_NAMESPACES.CTS.term("about"), child.get('urn')) _parse_structured_metadata(obj, xml)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '6', 'type': 'block', 'children': ['7', '16', '24', '45', '68', '94', '159', '184', '234', '252', '307', '336', '357']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '14']},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'setup'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'handlers'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '37']},{'id': '26', 'type': 'attribute', 'children': ['27', '36']},{'id': '27', 'type': 'attribute', 'children': ['28', '35']},{'id': '28', 'type': 'attribute', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'jinja2'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'template_folders'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'PLUGIN_ROOT'},{'id': '44', 'type': 'string', 'children': [], 'value': "'templates'"},{'id': '45', 'type': 'decorated_definition', 'children': ['46', '54']},{'id': '46', 'type': 'decorator', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'jinja2'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '54', 'type': 'function_definition', 'children': ['55', '56', '62']},{'id': '55', 'type': 'function_name', 'children': [], 'value': 'admtest'},{'id': '56', 'type': 'parameters', 'children': ['57', '58', '59']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '59', 'type': 'default_parameter', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '61', 'type': 'None', 'children': []},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'conditional_expression', 'children': ['65', '66', '67'], 'value': 'if'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '68', 'type': 'decorated_definition', 'children': ['69', '77']},{'id': '69', 'type': 'decorator', 'children': ['70']},{'id': '70', 'type': 'attribute', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'jinja2'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '77', 'type': 'function_definition', 'children': ['78', '79', '85']},{'id': '78', 'type': 'function_name', 'children': [], 'value': 'admeq'},{'id': '79', 'type': 'parameters', 'children': ['80', '81', '82']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '82', 'type': 'default_parameter', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '84', 'type': 'True', 'children': []},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'return_statement', 'children': ['87']},{'id': '87', 'type': 'conditional_expression', 'children': ['88', '89', '92'], 'value': 'if'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': '=='},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '92', 'type': 'not_operator', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '94', 'type': 'decorated_definition', 'children': ['95', '103']},{'id': '95', 'type': 'decorator', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '102']},{'id': '97', 'type': 'attribute', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'jinja2'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '103', 'type': 'function_definition', 'children': ['104', '105', '108']},{'id': '104', 'type': 'function_name', 'children': [], 'value': 'admurl'},{'id': '105', 'type': 'parameters', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '108', 'type': 'block', 'children': ['109', '135', '146']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '112', 'type': 'dictionary_comprehension', 'children': ['113', '116', '127']},{'id': '113', 'type': 'pair', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '116', 'type': 'for_in_clause', 'children': ['117', '120']},{'id': '117', 'type': 'pattern_list', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '120', 'type': 'call', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'if_clause', 'children': ['128']},{'id': '128', 'type': 'not_operator', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '135', 'type': 'if_statement', 'children': ['136', '138']},{'id': '136', 'type': 'not_operator', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '142', 'type': 'dictionary', 'children': ['143']},{'id': '143', 'type': 'pair', 'children': ['144', '145']},{'id': '144', 'type': 'string', 'children': [], 'value': "'ap'"},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '%'},{'id': '148', 'type': 'string', 'children': [], 'value': '"%s?%s"'},{'id': '149', 'type': 'tuple', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '159', 'type': 'if_statement', 'children': ['160', '167']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '166'], 'value': 'is'},{'id': '161', 'type': 'attribute', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '166', 'type': 'None', 'children': []},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '175']},{'id': '170', 'type': 'attribute', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '%'},{'id': '176', 'type': 'string', 'children': [], 'value': '"%s admin"'},{'id': '177', 'type': 'call', 'children': ['178', '183']},{'id': '178', 'type': 'attribute', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '183', 'type': 'argument_list', 'children': []},{'id': '184', 'type': 'if_statement', 'children': ['185', '194']},{'id': '185', 'type': 'not_operator', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'attribute', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'home'},{'id': '194', 'type': 'block', 'children': ['195', '226']},{'id': '195', 'type': 'function_definition', 'children': ['196', '197', '199']},{'id': '196', 'type': 'function_name', 'children': [], 'value': 'admin_home'},{'id': '197', 'type': 'parameters', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '199', 'type': 'block', 'children': ['200', '208']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'yield', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'authorize'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '208', 'type': 'return_statement', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '217']},{'id': '210', 'type': 'attribute', 'children': ['211', '216']},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'jinja2'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'render'},{'id': '217', 'type': 'argument_list', 'children': ['218', '223']},{'id': '218', 'type': 'attribute', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'template_home'},{'id': '223', 'type': 'keyword_argument', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '225', 'type': 'None', 'children': []},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '233']},{'id': '228', 'type': 'attribute', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'home'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'admin_home'},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '246']},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'attribute', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'home'},{'id': '252', 'type': 'if_statement', 'children': ['253', '259']},{'id': '253', 'type': 'not_operator', 'children': ['254']},{'id': '254', 'type': 'attribute', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'i18n'},{'id': '259', 'type': 'block', 'children': ['260', '306']},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '273']},{'id': '262', 'type': 'attribute', 'children': ['263', '272']},{'id': '263', 'type': 'attribute', 'children': ['264', '271']},{'id': '264', 'type': 'attribute', 'children': ['265', '270']},{'id': '265', 'type': 'attribute', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'jinja2'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'globals'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'dictionary', 'children': ['275', '281', '287']},{'id': '275', 'type': 'pair', 'children': ['276', '277']},{'id': '276', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '277', 'type': 'lambda', 'children': ['278', '280']},{'id': '278', 'type': 'lambda_parameters', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '281', 'type': 'pair', 'children': ['282', '283']},{'id': '282', 'type': 'string', 'children': [], 'value': "'gettext'"},{'id': '283', 'type': 'lambda', 'children': ['284', '286']},{'id': '284', 'type': 'lambda_parameters', 'children': ['285']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '287', 'type': 'pair', 'children': ['288', '289']},{'id': '288', 'type': 'string', 'children': [], 'value': "'ngettext'"},{'id': '289', 'type': 'lambda', 'children': ['290', '294']},{'id': '290', 'type': 'lambda_parameters', 'children': ['291', '292', '293']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '294', 'type': 'subscript', 'children': ['295', '305']},{'id': '295', 'type': '()', 'children': ['296']},{'id': '296', 'type': 'boolean_operator', 'children': ['297', '303'], 'value': 'or'},{'id': '297', 'type': 'boolean_operator', 'children': ['298', '301'], 'value': 'and'},{'id': '298', 'type': 'comparison_operator', 'children': ['299', '300'], 'value': '!='},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '300', 'type': 'integer', 'children': [], 'value': '1'},{'id': '301', 'type': 'tuple', 'children': ['302']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '303', 'type': 'tuple', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '305', 'type': 'integer', 'children': [], 'value': '0'},{'id': '306', 'type': 'return_statement', 'children': []},{'id': '307', 'type': 'if_statement', 'children': ['308', '324']},{'id': '308', 'type': 'boolean_operator', 'children': ['309', '314'], 'value': 'or'},{'id': '309', 'type': 'comparison_operator', 'children': ['310', '311'], 'value': 'not'},{'id': '310', 'type': 'string', 'children': [], 'value': "'babel'"},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '314', 'type': 'not_operator', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '317', 'type': 'argument_list', 'children': ['318', '323']},{'id': '318', 'type': 'attribute', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'babel'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'BPlugin'},{'id': '324', 'type': 'block', 'children': ['325']},{'id': '325', 'type': 'raise_statement', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'PluginException'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'binary_operator', 'children': ['330', '331'], 'value': '%'},{'id': '330', 'type': 'string', 'children': [], 'value': "'Plugin `%s` requires for plugin `%s` to be installed to the application.'"},{'id': '331', 'type': 'tuple', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'BPlugin'},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'call', 'children': ['338', '349']},{'id': '338', 'type': 'attribute', 'children': ['339', '348']},{'id': '339', 'type': 'attribute', 'children': ['340', '347']},{'id': '340', 'type': 'attribute', 'children': ['341', '346']},{'id': '341', 'type': 'attribute', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'babel'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'locales_dirs'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '354', 'type': 'argument_list', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'PLUGIN_ROOT'},{'id': '356', 'type': 'string', 'children': [], 'value': "'locales'"},{'id': '357', 'type': 'if_statement', 'children': ['358', '366']},{'id': '358', 'type': 'not_operator', 'children': ['359']},{'id': '359', 'type': 'attribute', 'children': ['360', '365']},{'id': '360', 'type': 'attribute', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'babel'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'locale_selector_func'},{'id': '366', 'type': 'block', 'children': ['367']},{'id': '367', 'type': 'expression_statement', 'children': ['368']},{'id': '368', 'type': 'assignment', 'children': ['369', '376']},{'id': '369', 'type': 'attribute', 'children': ['370', '375']},{'id': '370', 'type': 'attribute', 'children': ['371', '374']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'babel'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'locale_selector_func'},{'id': '376', 'type': 'attribute', 'children': ['377', '382']},{'id': '377', 'type': 'attribute', 'children': ['378', '381']},{'id': '378', 'type': 'attribute', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'babel'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'select_locale_by_request'}
def setup(self, app): super().setup(app) self.handlers = OrderedDict() app.ps.jinja2.cfg.template_folders.append(op.join(PLUGIN_ROOT, 'templates')) @app.ps.jinja2.filter def admtest(value, a, b=None): return a if value else b @app.ps.jinja2.filter def admeq(a, b, result=True): return result if a == b else not result @app.ps.jinja2.register def admurl(request, prefix): qs = {k: v for k, v in request.query.items() if not k.startswith(prefix)} if not qs: qs = {'ap': 0} return "%s?%s" % (request.path, urlparse.urlencode(qs)) if self.cfg.name is None: self.cfg.name = "%s admin" % app.name.title() if not callable(self.cfg.home): def admin_home(request): yield from self.authorize(request) return app.ps.jinja2.render(self.cfg.template_home, active=None) self.cfg.home = admin_home app.register(self.cfg.prefix)(self.cfg.home) if not self.cfg.i18n: app.ps.jinja2.env.globals.update({ '_': lambda s: s, 'gettext': lambda s: s, 'ngettext': lambda s, p, n: (n != 1 and (p,) or (s,))[0], }) return if 'babel' not in app.ps or not isinstance(app.ps.babel, BPlugin): raise PluginException( 'Plugin `%s` requires for plugin `%s` to be installed to the application.' % ( self.name, BPlugin)) app.ps.babel.cfg.locales_dirs.append(op.join(PLUGIN_ROOT, 'locales')) if not app.ps.babel.locale_selector_func: app.ps.babel.locale_selector_func = app.ps.babel.select_locale_by_request
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'passageLoop'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'new_tree'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'xpath1'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'xpath2'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'preceding_siblings'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'following_siblings'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '26', '395']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '22']},{'id': '19', 'type': 'pattern_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'current_1'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'queue_1'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': '__formatXpath__'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'xpath1'},{'id': '26', 'type': 'if_statement', 'children': ['27', '30', '152']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'xpath2'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'block', 'children': ['31', '41', '50', '54', '63']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'pattern_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'result_1'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'performXpath'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'current_1'},{'id': '41', 'type': 'if_statement', 'children': ['42', '45']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '44', 'type': 'True', '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': 'queue_1'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'xpath1'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'central'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'has_no_queue'},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '62'], 'value': '=='},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'queue_1'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'if_statement', 'children': ['64', '67']},{'id': '64', 'type': 'boolean_operator', 'children': ['65', '66'], 'value': 'or'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'preceding_siblings'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'following_siblings'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'for_statement', 'children': ['69', '70', '74']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sibling'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'xmliter'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'if_statement', 'children': ['76', '79', '119', '136']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '=='},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sibling'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'result_1'},{'id': '79', 'type': 'block', 'children': ['80', '84', '97', '115']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'central'},{'id': '83', 'type': 'True', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'copyNode'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91', '94']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'result_1'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'has_no_queue'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'new_tree'},{'id': '97', 'type': 'if_statement', 'children': ['98', '100']},{'id': '98', 'type': 'not_operator', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'has_no_queue'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'passageLoop'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106', '107', '108', '109', '112']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'result_1'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'queue_1'},{'id': '108', 'type': 'None', 'children': []},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'preceding_siblings'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'preceding_siblings'},{'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'following_siblings'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'following_siblings'},{'id': '115', 'type': 'if_statement', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'preceding_siblings'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'break_statement', 'children': []},{'id': '119', 'type': 'elif_clause', 'children': ['120', '124']},{'id': '120', 'type': 'boolean_operator', 'children': ['121', '123'], 'value': 'and'},{'id': '121', 'type': 'not_operator', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'central'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'preceding_siblings'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'copyNode'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130', '133']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'sibling'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'new_tree'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '135', 'type': 'True', 'children': []},{'id': '136', 'type': 'elif_clause', 'children': ['137', '140']},{'id': '137', 'type': 'boolean_operator', 'children': ['138', '139'], 'value': 'and'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'central'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'following_siblings'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'copyNode'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146', '149']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sibling'},{'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'new_tree'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '151', 'type': 'True', 'children': []},{'id': '152', 'type': 'else_clause', 'children': ['153']},{'id': '153', 'type': 'block', 'children': ['154', '164', '208', '238']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '159']},{'id': '156', 'type': 'pattern_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'result_1'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'performXpath'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'current_1'},{'id': '164', 'type': 'if_statement', 'children': ['165', '168', '197']},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': 'is'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '167', 'type': 'True', 'children': []},{'id': '168', 'type': 'block', 'children': ['169', '173']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'queue_1'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'xpath1'},{'id': '173', 'type': 'if_statement', 'children': ['174', '177', '186']},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': '=='},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'xpath2'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'xpath1'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '183']},{'id': '180', 'type': 'pattern_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'current_2'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'queue_2'},{'id': '183', 'type': 'expression_list', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'current_1'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'queue_1'},{'id': '186', 'type': 'else_clause', 'children': ['187']},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '193']},{'id': '190', 'type': 'pattern_list', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'current_2'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'queue_2'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': '__formatXpath__'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'xpath2'},{'id': '197', 'type': 'else_clause', 'children': ['198']},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '204']},{'id': '201', 'type': 'pattern_list', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'current_2'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'queue_2'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': '__formatXpath__'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'xpath2'},{'id': '208', 'type': 'if_statement', 'children': ['209', '212', '232']},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '211'], 'value': '!='},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'xpath1'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'xpath2'},{'id': '212', 'type': 'block', 'children': ['213', '223']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '218']},{'id': '215', 'type': 'pattern_list', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'result_2'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'performXpath'},{'id': '220', 'type': 'argument_list', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'current_2'},{'id': '223', 'type': 'if_statement', 'children': ['224', '227']},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': 'is'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '226', 'type': 'True', 'children': []},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'queue_2'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'xpath2'},{'id': '232', 'type': 'else_clause', 'children': ['233']},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'result_2'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'result_1'},{'id': '238', 'type': 'if_statement', 'children': ['239', '242', '277']},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': '=='},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'result_1'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'result_2'},{'id': '242', 'type': 'block', 'children': ['243', '252', '265']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'has_no_queue'},{'id': '246', 'type': 'comparison_operator', 'children': ['247', '251'], 'value': '=='},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'queue_1'},{'id': '251', 'type': 'integer', 'children': [], 'value': '0'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'copyNode'},{'id': '257', 'type': 'argument_list', 'children': ['258', '259', '262']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'result_1'},{'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'has_no_queue'},{'id': '262', 'type': 'keyword_argument', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'new_tree'},{'id': '265', 'type': 'if_statement', 'children': ['266', '268']},{'id': '266', 'type': 'not_operator', 'children': ['267']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'has_no_queue'},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'passageLoop'},{'id': '272', 'type': 'argument_list', 'children': ['273', '274', '275', '276']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'result_1'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'queue_1'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'queue_2'},{'id': '277', 'type': 'else_clause', 'children': ['278']},{'id': '278', 'type': 'block', 'children': ['279', '283', '358', '367', '380']},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'assignment', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '282', 'type': 'False', 'children': []},{'id': '283', 'type': 'for_statement', 'children': ['284', '285', '289']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'sibling'},{'id': '285', 'type': 'call', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'xmliter'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'if_statement', 'children': ['291', '292', '312']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '292', 'type': 'block', 'children': ['293']},{'id': '293', 'type': 'if_statement', 'children': ['294', '297', '299']},{'id': '294', 'type': 'comparison_operator', 'children': ['295', '296'], 'value': '=='},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'sibling'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'result_2'},{'id': '297', 'type': 'block', 'children': ['298']},{'id': '298', 'type': 'break_statement', 'children': []},{'id': '299', 'type': 'else_clause', 'children': ['300']},{'id': '300', 'type': 'block', 'children': ['301']},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'call', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'copyNode'},{'id': '304', 'type': 'argument_list', 'children': ['305', '306', '309']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'sibling'},{'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'new_tree'},{'id': '309', 'type': 'keyword_argument', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '311', 'type': 'True', 'children': []},{'id': '312', 'type': 'elif_clause', 'children': ['313', '316']},{'id': '313', 'type': 'comparison_operator', 'children': ['314', '315'], 'value': '=='},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'sibling'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'result_1'},{'id': '316', 'type': 'block', 'children': ['317', '321', '330', '343']},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'assignment', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '320', 'type': 'True', 'children': []},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'assignment', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'has_no_queue_1'},{'id': '324', 'type': 'comparison_operator', 'children': ['325', '329'], 'value': '=='},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'queue_1'},{'id': '329', 'type': 'integer', 'children': [], 'value': '0'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '333', 'type': 'call', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'copyNode'},{'id': '335', 'type': 'argument_list', 'children': ['336', '337', '340']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'sibling'},{'id': '337', 'type': 'keyword_argument', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'has_no_queue_1'},{'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'new_tree'},{'id': '343', 'type': 'if_statement', 'children': ['344', '346']},{'id': '344', 'type': 'not_operator', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'has_no_queue_1'},{'id': '346', 'type': 'block', 'children': ['347']},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'call', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'passageLoop'},{'id': '350', 'type': 'argument_list', 'children': ['351', '352', '353', '354', '355']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'sibling'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'queue_1'},{'id': '354', 'type': 'None', 'children': []},{'id': '355', 'type': 'keyword_argument', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'following_siblings'},{'id': '357', 'type': 'True', 'children': []},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'assignment', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'continue_loop'},{'id': '361', 'type': 'comparison_operator', 'children': ['362', '366'], 'value': '=='},{'id': '362', 'type': 'call', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'queue_2'},{'id': '366', 'type': 'integer', 'children': [], 'value': '0'},{'id': '367', 'type': 'expression_statement', 'children': ['368']},{'id': '368', 'type': 'assignment', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'copyNode'},{'id': '372', 'type': 'argument_list', 'children': ['373', '374', '377']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'result_2'},{'id': '374', 'type': 'keyword_argument', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'continue_loop'},{'id': '377', 'type': 'keyword_argument', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'new_tree'},{'id': '380', 'type': 'if_statement', 'children': ['381', '383']},{'id': '381', 'type': 'not_operator', 'children': ['382']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'continue_loop'},{'id': '383', 'type': 'block', 'children': ['384']},{'id': '384', 'type': 'expression_statement', 'children': ['385']},{'id': '385', 'type': 'call', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'passageLoop'},{'id': '387', 'type': 'argument_list', 'children': ['388', '389', '390', '391', '392']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'result_2'},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'queue_2'},{'id': '391', 'type': 'None', 'children': []},{'id': '392', 'type': 'keyword_argument', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'preceding_siblings'},{'id': '394', 'type': 'True', 'children': []},{'id': '395', 'type': 'return_statement', 'children': ['396']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'new_tree'}
def passageLoop(parent, new_tree, xpath1, xpath2=None, preceding_siblings=False, following_siblings=False): current_1, queue_1 = __formatXpath__(xpath1) if xpath2 is None: result_1, loop = performXpath(parent, current_1) if loop is True: queue_1 = xpath1 central = None has_no_queue = len(queue_1) == 0 if preceding_siblings or following_siblings: for sibling in xmliter(parent): if sibling == result_1: central = True child = copyNode(result_1, children=has_no_queue, parent=new_tree) if not has_no_queue: passageLoop( result_1, child, queue_1, None, preceding_siblings=preceding_siblings, following_siblings=following_siblings ) if preceding_siblings: break elif not central and preceding_siblings: copyNode(sibling, parent=new_tree, children=True) elif central and following_siblings: copyNode(sibling, parent=new_tree, children=True) else: result_1, loop = performXpath(parent, current_1) if loop is True: queue_1 = xpath1 if xpath2 == xpath1: current_2, queue_2 = current_1, queue_1 else: current_2, queue_2 = __formatXpath__(xpath2) else: current_2, queue_2 = __formatXpath__(xpath2) if xpath1 != xpath2: result_2, loop = performXpath(parent, current_2) if loop is True: queue_2 = xpath2 else: result_2 = result_1 if result_1 == result_2: has_no_queue = len(queue_1) == 0 child = copyNode(result_1, children=has_no_queue, parent=new_tree) if not has_no_queue: passageLoop( result_1, child, queue_1, queue_2 ) else: start = False for sibling in xmliter(parent): if start: if sibling == result_2: break else: copyNode(sibling, parent=new_tree, children=True) elif sibling == result_1: start = True has_no_queue_1 = len(queue_1) == 0 node = copyNode(sibling, children=has_no_queue_1, parent=new_tree) if not has_no_queue_1: passageLoop(sibling, node, queue_1, None, following_siblings=True) continue_loop = len(queue_2) == 0 node = copyNode(result_2, children=continue_loop, parent=new_tree) if not continue_loop: passageLoop(result_2, node, queue_2, None, preceding_siblings=True) return new_tree
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cancellable_wait'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '8']},{'id': '6', 'type': 'list_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'awaitables'},{'id': '8', 'type': 'type', 'children': ['9']},{'id': '9', 'type': 'generic_type', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'Awaitable'},{'id': '11', 'type': 'type_parameter', 'children': ['12']},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_R'},{'id': '14', 'type': 'typed_default_parameter', 'children': ['15', '16', '18']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'type', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_R'},{'id': '21', 'type': 'block', 'children': ['22', '47', '92', '102', '110', '139']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '25', 'type': 'list_comprehension', 'children': ['26', '37']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ensure_future'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '+'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'awaitables'},{'id': '41', 'type': 'tuple', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'try_statement', 'children': ['48', '74']},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '54']},{'id': '51', 'type': 'pattern_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'pending'},{'id': '54', 'type': 'await', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61', '64', '69']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'return_when'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'FIRST_COMPLETED'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '74', 'type': 'except_clause', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'CancelledError'},{'id': '80', 'type': 'block', 'children': ['81', '91']},{'id': '81', 'type': 'for_statement', 'children': ['82', '83', '84']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'futures'},{'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': 'future'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'cancel'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'raise_statement', 'children': []},{'id': '92', 'type': 'for_statement', 'children': ['93', '94', '95']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'pending'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'cancel'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'if_statement', 'children': ['103', '105']},{'id': '103', 'type': 'not_operator', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'raise_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'TimeoutError'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'if_statement', 'children': ['111', '116']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': 'is'},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'triggered_token'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'block', 'children': ['117', '127']},{'id': '117', 'type': 'for_statement', 'children': ['118', '119', '120']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'raise_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'OperationCancelled'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': '"Cancellation requested by {} token"'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'triggered_token'},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '148']},{'id': '141', 'type': 'attribute', 'children': ['142', '147']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '148', 'type': 'argument_list', 'children': []}
async def cancellable_wait(self, *awaitables: Awaitable[_R], timeout: float = None) -> _R: futures = [asyncio.ensure_future(a, loop=self.loop) for a in awaitables + (self.wait(),)] try: done, pending = await asyncio.wait( futures, timeout=timeout, return_when=asyncio.FIRST_COMPLETED, loop=self.loop, ) except asyncio.futures.CancelledError: for future in futures: future.cancel() raise for task in pending: task.cancel() if not done: raise TimeoutError() if self.triggered_token is not None: for task in done: task.exception() raise OperationCancelled( "Cancellation requested by {} token".format(self.triggered_token) ) return done.pop().result()
{'id': '0', 'type': 'module', 'children': ['1', '10', '12', '23', '29', '33', '37', '210', '218', '227', '245']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_tweets_count_times'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': [], 'value': ''},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '17']},{'id': '14', 'type': 'pattern_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'newest_id'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_get_oldest_id'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'newest_id'},{'id': '26', 'type': 'boolean_operator', 'children': ['27', '28'], 'value': 'or'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'newest_id'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'all_tweets'},{'id': '32', 'type': 'list', 'children': [], 'value': '[]'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'while_statement', 'children': ['38', '41']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '<'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '41', 'type': 'block', 'children': ['42', '46', '96', '105', '114', '151', '158', '168', '178', '192']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'augmented_assignment', 'children': ['44', '45'], 'value': '+='},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '45', 'type': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'if_statement', 'children': ['47', '50', '71']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '<='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'newest_id'},{'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': 'tweets'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'get_tweets'},{'id': '56', 'type': 'argument_list', 'children': ['57', '60', '65', '68']},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'max_id'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '-'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'TWEETS_PER_SEARCH'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tweets'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_tweets'},{'id': '78', 'type': 'argument_list', 'children': ['79', '82', '87', '90', '93']},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'max_id'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '-'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'since_id'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'newest_id'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'TWEETS_PER_SEARCH'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'rate_limit_remaining'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'get_lastfunction_header'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': "'x-rate-limit-remaining'"},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'rate_limit_reset'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'get_lastfunction_header'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'string', 'children': [], 'value': "'x-rate-limit-reset'"},{'id': '114', 'type': 'if_statement', 'children': ['115', '120', '138']},{'id': '115', 'type': 'not_operator', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'tweets'},{'id': '120', 'type': 'block', 'children': ['121', '137']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '+'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '136'], 'value': '*'},{'id': '127', 'type': '()', 'children': ['128']},{'id': '128', 'type': 'binary_operator', 'children': ['129', '135'], 'value': '+'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '134'], 'value': '-'},{'id': '130', 'type': '()', 'children': ['131']},{'id': '131', 'type': 'boolean_operator', 'children': ['132', '133'], 'value': 'or'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'newest_id'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '135', 'type': 'integer', 'children': [], 'value': '1'},{'id': '136', 'type': 'integer', 'children': [], 'value': '10000'},{'id': '137', 'type': 'break_statement', 'children': []},{'id': '138', 'type': 'elif_clause', 'children': ['139', '144']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'tweets'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '144', 'type': 'block', 'children': ['145', '150']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'tweets'},{'id': '150', 'type': 'break_statement', 'children': []},{'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': 'all_tweets'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'tweets'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'tweet_ids'},{'id': '161', 'type': 'set_comprehension', 'children': ['162', '165']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '164', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '165', 'type': 'for_in_clause', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'tweets'},{'id': '168', 'type': 'if_statement', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'tweet_ids'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '183']},{'id': '180', 'type': 'pattern_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'newest_id'},{'id': '183', 'type': 'expression_list', 'children': ['184', '188']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'tweet_ids'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'tweet_ids'},{'id': '192', 'type': 'if_statement', 'children': ['193', '196']},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': '=='},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'rate_limit_remaining'},{'id': '195', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'time'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'binary_operator', 'children': ['204', '205'], 'value': '-'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'rate_limit_reset'},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'save_tweets'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'all_tweets'},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': '_set_oldest_id'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223', '224']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'oldest_id'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'newest_id'},{'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '227', 'type': 'if_statement', 'children': ['228', '234']},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '233'], 'value': '=='},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'all_tweets'},{'id': '233', 'type': 'integer', 'children': [], 'value': '0'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'make_oldest_id_path'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '245', 'type': 'return_statement', 'children': ['246']},{'id': '246', 'type': 'expression_list', 'children': ['247', '251']},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'all_tweets'},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'twitter'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'get_lastfunction_header'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'string', 'children': [], 'value': "'x-rate-limit-remaining'"}
def get_tweets_count_times(twitter, count, query=None): r oldest_id, newest_id = _get_oldest_id(query=query) newest_id = newest_id or oldest_id all_tweets = [] i = 0 while i < count: i += 1 if oldest_id <= newest_id: tweets = get_tweets(query=query, max_id=oldest_id - 1, count=TWEETS_PER_SEARCH, twitter=twitter) else: tweets = get_tweets(query=query, max_id=oldest_id - 1, since_id=newest_id, count=TWEETS_PER_SEARCH, twitter=twitter) rate_limit_remaining = twitter.get_lastfunction_header('x-rate-limit-remaining') rate_limit_reset = twitter.get_lastfunction_header('x-rate-limit-reset') if not len(tweets): oldest_id = oldest_id + ((newest_id or oldest_id) - oldest_id + 1) * 10000 break elif isinstance(tweets, dict): print(tweets) break all_tweets.extend(tweets) tweet_ids = {t['id'] for t in tweets} if oldest_id: tweet_ids.add(oldest_id) oldest_id, newest_id = min(tweet_ids), max(tweet_ids) if rate_limit_remaining == 1: time.sleep(rate_limit_reset - time.time()) save_tweets(all_tweets, query=query) _set_oldest_id(oldest_id, newest_id, query=query) if len(all_tweets) == 0: os.remove(make_oldest_id_path(query)) return len(all_tweets), twitter.get_lastfunction_header('x-rate-limit-remaining')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'register'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'hash_name'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'hash_new'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '26', '42', '70', '84']},{'id': '14', 'type': 'if_statement', 'children': ['15', '20']},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_is_app_specific_func'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'raise_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': '"only application-specific functions can be registered"'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'name_mapping_data'},{'id': '29', 'type': 'list', 'children': ['30', '36'], 'value': '[\n (cls._func_from_name, name,\n "function name is already registered for a different function"),\n (cls._func_from_hash, hash_name,\n "hashlib name is already registered for a different function")]'},{'id': '30', 'type': 'tuple', 'children': ['31', '34', '35']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_func_from_name'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'string', 'children': [], 'value': '"function name is already registered for a different function"'},{'id': '36', 'type': 'tuple', 'children': ['37', '40', '41']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_func_from_hash'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'hash_name'},{'id': '41', 'type': 'string', 'children': [], 'value': '"hashlib name is already registered for a different function"'},{'id': '42', 'type': 'for_statement', 'children': ['43', '47', '48']},{'id': '43', 'type': 'tuple_pattern', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'nameinmap'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'errmsg'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'name_mapping_data'},{'id': '48', 'type': 'block', 'children': ['49', '59']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'existing_func'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'nameinmap'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '!='},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'existing_func'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'raise_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'errmsg'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'existing_func'},{'id': '70', 'type': 'if_statement', 'children': ['71', '76']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'in'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '75', 'type': 'identifier', 'children': [], 'value': '_func_hash'},{'id': '76', 'type': 'block', 'children': ['77']},{'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': 'cls'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'unregister'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_do_register'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91', '92', '93']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'hash_name'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'hash_new'}
def register(cls, code, name, hash_name=None, hash_new=None): if not _is_app_specific_func(code): raise ValueError( "only application-specific functions can be registered") name_mapping_data = [ (cls._func_from_name, name, "function name is already registered for a different function"), (cls._func_from_hash, hash_name, "hashlib name is already registered for a different function")] for (mapping, nameinmap, errmsg) in name_mapping_data: existing_func = mapping.get(nameinmap, code) if existing_func != code: raise ValueError(errmsg, existing_func) if code in cls._func_hash: cls.unregister(code) cls._do_register(code, name, hash_name, hash_new)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compile_vocab'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '7', 'type': 'float', 'children': [], 'value': '1e6'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'tokenizer'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Tokenizer'},{'id': '15', 'type': 'argument_list', 'children': ['16', '19', '22']},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'stem'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '33', '39', '67', '170']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'tokenizer'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'make_tokenizer'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'tokenizer'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'Dictionary'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'try_statement', 'children': ['40', '61']},{'id': '40', 'type': 'block', 'children': ['41', '53']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'except_clause', 'children': ['62', '65']},{'id': '62', 'type': 'tuple', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'pass_statement', 'children': []},{'id': '67', 'type': 'for_statement', 'children': ['68', '71', '75']},{'id': '68', 'type': 'pattern_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'docs'},{'id': '75', 'type': 'block', 'children': ['76', '122', '128', '142']},{'id': '76', 'type': 'try_statement', 'children': ['77', '86']},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'except_clause', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'if_statement', 'children': ['90', '96', '113']},{'id': '90', 'type': 'not_operator', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "' '"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'list_comprehension', 'children': ['106', '110']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '110', 'type': 'for_in_clause', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '113', 'type': 'else_clause', 'children': ['114']},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '122', 'type': 'if_statement', 'children': ['123', '126']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '>='},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'break_statement', 'children': []},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'add_documents'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'list', 'children': ['135'], 'value': '[list(tokenizer(doc))]'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'tokenizer'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '142', 'type': 'if_statement', 'children': ['143', '149']},{'id': '143', 'type': 'boolean_operator', 'children': ['144', '145'], 'value': 'and'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '145', 'type': 'not_operator', 'children': ['146']},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '%'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '148', 'type': 'integer', 'children': [], 'value': '100'},{'id': '149', 'type': 'block', 'children': ['150']},{'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': 'log'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'string', 'children': [], 'value': "'{}: {}'"},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '162', 'type': 'subscript', 'children': ['163', '167']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '167', 'type': 'slice', 'children': ['168', '169']},{'id': '168', 'type': 'colon', 'children': []},{'id': '169', 'type': 'integer', 'children': [], 'value': '120'},{'id': '170', 'type': 'return_statement', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'd'}
def compile_vocab(docs, limit=1e6, verbose=0, tokenizer=Tokenizer(stem=None, lower=None, strip=None)): tokenizer = make_tokenizer(tokenizer) d = Dictionary() try: limit = min(limit, docs.count()) docs = docs.iterator() except (AttributeError, TypeError): pass for i, doc in enumerate(docs): try: doc = doc.values() except AttributeError: if not isinstance(doc, str): doc = ' '.join([str(v) for v in doc]) else: doc = str(doc) if i >= limit: break d.add_documents([list(tokenizer(doc))]) if verbose and not i % 100: log.info('{}: {}'.format(i, repr(d)[:120])) return d
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '6', 'type': 'block', 'children': ['7', '11', '15', '19', '61', '118', '141', '155', '162', '172']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'textgroups'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'texts'},{'id': '14', 'type': 'list', 'children': [], 'value': '[]'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'invalids'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '22', 'type': 'block', 'children': ['23', '37']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'cts_files'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': '"{base_folder}/data/*/__cts__.xml"'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'base_folder'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cts_file'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cts_files'},{'id': '40', 'type': 'block', 'children': ['41', '52']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '46']},{'id': '43', 'type': 'pattern_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'textgroup'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'cts_file'},{'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_textgroup'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'cts_file'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'textgroups'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'tuple', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'textgroup'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'cts_file'},{'id': '61', 'type': 'for_statement', 'children': ['62', '65', '66']},{'id': '62', 'type': 'pattern_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'textgroup'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'cts_textgroup_file'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'textgroups'},{'id': '66', 'type': 'block', 'children': ['67', '88']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'cts_work_files'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': '"{parent}/*/__cts__.xml"'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'cts_textgroup_file'},{'id': '88', 'type': 'for_statement', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'cts_work_file'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'cts_work_files'},{'id': '91', 'type': 'block', 'children': ['92', '105']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '98']},{'id': '94', 'type': 'pattern_list', 'children': ['95', '96', '97']},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'parsed_texts'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_parse_work'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'cts_work_file'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'textgroup'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'texts'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'list_comprehension', 'children': ['112', '115']},{'id': '112', 'type': 'tuple', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '115', 'type': 'for_in_clause', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'parsed_texts'},{'id': '118', 'type': 'for_statement', 'children': ['119', '122', '123']},{'id': '119', 'type': 'pattern_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'texts'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'if_statement', 'children': ['125', '133']},{'id': '125', 'type': 'not_operator', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_parse_text'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'invalids'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '141', 'type': 'for_statement', 'children': ['142', '145', '146']},{'id': '142', 'type': 'pattern_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'textgroup'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'textgroup_path'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'textgroups'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_dispatch_container'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'textgroup'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'textgroup_path'},{'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': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': '_clean_invalids'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'invalids'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'inventory'},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'dispatcher'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '172', 'type': 'return_statement', 'children': ['173']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'inventory'}
def parse(self, resource): textgroups = [] texts = [] invalids = [] for folder in resource: cts_files = glob("{base_folder}/data/*/__cts__.xml".format(base_folder=folder)) for cts_file in cts_files: textgroup, cts_file = self._parse_textgroup(cts_file) textgroups.append((textgroup, cts_file)) for textgroup, cts_textgroup_file in textgroups: cts_work_files = glob("{parent}/*/__cts__.xml".format(parent=os.path.dirname(cts_textgroup_file))) for cts_work_file in cts_work_files: _, parsed_texts, directory = self._parse_work(cts_work_file, textgroup) texts.extend([(text, directory) for text in parsed_texts]) for text, directory in texts: if not self._parse_text(text, directory): invalids.append(text) for textgroup, textgroup_path in textgroups: self._dispatch_container(textgroup, textgroup_path) self._clean_invalids(invalids) self.inventory = self.dispatcher.collection return self.inventory
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_address_label'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '22', '38', '56', '81', '95', '128', '138']},{'id': '6', 'type': 'if_statement', 'children': ['7', '10']},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'organisation_name'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', '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': 'address_label'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'organisation_name'},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'department_name'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'address_label'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'department_name'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'po_box_number'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '50']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'address_label'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'},{'id': '52', 'type': 'string', 'children': [], 'value': "'PO Box '"},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'po_box_number'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '59', 'type': 'list', 'children': ['60', '63', '66', '69', '72', '75', '78'], 'value': '[\n self.sub_building_name,\n self.building_name,\n self.building_number,\n self.dependent_thoroughfare,\n self.thoroughfare,\n self.double_dependent_locality,\n self.dependent_locality,\n ]'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sub_building_name'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'building_name'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'building_number'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dependent_thoroughfare'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'thoroughfare'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'double_dependent_locality'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dependent_locality'},{'id': '81', 'type': 'for_statement', 'children': ['82', '83', '84']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'if_statement', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'element'},{'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': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_append_to_label'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '95', 'type': 'if_statement', 'children': ['96', '104']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '103'], 'value': '<'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'address_label'},{'id': '103', 'type': 'integer', 'children': [], 'value': '7'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'for_statement', 'children': ['106', '107', '118']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'binary_operator', 'children': ['111', '112'], 'value': '-'},{'id': '111', 'type': 'integer', 'children': [], 'value': '7'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'address_label'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'address_label'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'string', 'children': [], 'value': "''"},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '135']},{'id': '130', 'type': 'subscript', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'address_label'},{'id': '134', 'type': 'integer', 'children': [], 'value': '5'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'post_town'},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': '", "'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'list_comprehension', 'children': ['145', '146', '151']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '146', 'type': 'for_in_clause', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'address_label'},{'id': '151', 'type': 'if_clause', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'f'}
def generate_address_label(self): if self.organisation_name: self.address_label.append(self.organisation_name) if self.department_name: self.address_label.append(self.department_name) if self.po_box_number: self.address_label.append('PO Box ' + self.po_box_number) elements = [ self.sub_building_name, self.building_name, self.building_number, self.dependent_thoroughfare, self.thoroughfare, self.double_dependent_locality, self.dependent_locality, ] for element in elements: if element: self._append_to_label(element) if len(self.address_label) < 7: for i in range(7 - len(self.address_label)): self.address_label.append('') self.address_label[5] = self.post_town return ", ".join([f for f in self.address_label if f])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'verify_token'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'public_key_or_address'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'signing_algorithm'},{'id': '8', 'type': 'string', 'children': [], 'value': '"ES256K"'},{'id': '9', 'type': 'block', 'children': ['10', '17', '23', '33', '45', '55', '67', '77', '88', '95', '102', '109', '184', '215', '221', '240']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'decoded_token'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'decode_token'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'decoded_token_payload'},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'decoded_token'},{'id': '22', 'type': 'string', 'children': [], 'value': '"payload"'},{'id': '23', 'type': 'if_statement', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'not'},{'id': '25', 'type': 'string', 'children': [], 'value': '"subject"'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'decoded_token_payload'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'raise_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': '"Token doesn\'t have a subject"'},{'id': '33', 'type': 'if_statement', 'children': ['34', '39']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'not'},{'id': '35', 'type': 'string', 'children': [], 'value': '"publicKey"'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'decoded_token_payload'},{'id': '38', 'type': 'string', 'children': [], 'value': '"subject"'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'raise_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': '"Token doesn\'t have a subject public key"'},{'id': '45', 'type': 'if_statement', 'children': ['46', '49']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'not'},{'id': '47', 'type': 'string', 'children': [], 'value': '"issuer"'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'decoded_token_payload'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'raise_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': '"Token doesn\'t have an issuer"'},{'id': '55', 'type': 'if_statement', 'children': ['56', '61']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'not'},{'id': '57', 'type': 'string', 'children': [], 'value': '"publicKey"'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'decoded_token_payload'},{'id': '60', 'type': 'string', 'children': [], 'value': '"issuer"'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'raise_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'string', 'children': [], 'value': '"Token doesn\'t have an issuer public key"'},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'not'},{'id': '69', 'type': 'string', 'children': [], 'value': '"claim"'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'decoded_token_payload'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'raise_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': '"Token doesn\'t have a claim"'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'issuer_public_key'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'subscript', 'children': ['84', '87']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'decoded_token_payload'},{'id': '86', 'type': 'string', 'children': [], 'value': '"issuer"'},{'id': '87', 'type': 'string', 'children': [], 'value': '"publicKey"'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'public_key_object'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ECPublicKey'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'issuer_public_key'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'compressed_public_key'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'compress'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'issuer_public_key'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'decompressed_public_key'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'decompress'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'issuer_public_key'},{'id': '109', 'type': 'if_statement', 'children': ['110', '117', '143', '177']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '114'], 'value': '=='},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'public_key_object'},{'id': '113', 'type': 'identifier', 'children': [], 'value': '_type'},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'PubkeyType'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'compressed'},{'id': '117', 'type': 'block', 'children': ['118', '126']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'compressed_address'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'public_key_object'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'uncompressed_address'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'bin_hash160_to_address'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'bin_hash160'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'decompress'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'public_key_object'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'to_bin'},{'id': '142', 'type': 'argument_list', 'children': []},{'id': '143', 'type': 'elif_clause', 'children': ['144', '151']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '148'], 'value': '=='},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'public_key_object'},{'id': '147', 'type': 'identifier', 'children': [], 'value': '_type'},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'PubkeyType'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'uncompressed'},{'id': '151', 'type': 'block', 'children': ['152', '169']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'compressed_address'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'bin_hash160_to_address'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'bin_hash160'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'compress'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'public_key_object'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'to_bin'},{'id': '168', 'type': 'argument_list', 'children': []},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'uncompressed_address'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'public_key_object'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'else_clause', 'children': ['178']},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'raise_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'string', 'children': [], 'value': '"Invalid issuer public key format"'},{'id': '184', 'type': 'if_statement', 'children': ['185', '188', '190', '196', '202', '208']},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': '=='},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'public_key_or_address'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'compressed_public_key'},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'pass_statement', 'children': []},{'id': '190', 'type': 'elif_clause', 'children': ['191', '194']},{'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': '=='},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'public_key_or_address'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'decompressed_public_key'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'pass_statement', 'children': []},{'id': '196', 'type': 'elif_clause', 'children': ['197', '200']},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': '=='},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'public_key_or_address'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'compressed_address'},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'pass_statement', 'children': []},{'id': '202', 'type': 'elif_clause', 'children': ['203', '206']},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': '=='},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'public_key_or_address'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'uncompressed_address'},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'pass_statement', 'children': []},{'id': '208', 'type': 'else_clause', 'children': ['209']},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'raise_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'string', 'children': [], 'value': '"Token public key doesn\'t match the verifying value"'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'token_verifier'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'TokenVerifier'},{'id': '220', 'type': 'argument_list', 'children': []},{'id': '221', 'type': 'if_statement', 'children': ['222', '234']},{'id': '222', 'type': 'not_operator', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'token_verifier'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'verify'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'public_key_object'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'to_pem'},{'id': '233', 'type': 'argument_list', 'children': []},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'raise_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'string', 'children': [], 'value': '"Token was not signed by the issuer public key"'},{'id': '240', 'type': 'return_statement', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'decoded_token'}
def verify_token(token, public_key_or_address, signing_algorithm="ES256K"): decoded_token = decode_token(token) decoded_token_payload = decoded_token["payload"] if "subject" not in decoded_token_payload: raise ValueError("Token doesn't have a subject") if "publicKey" not in decoded_token_payload["subject"]: raise ValueError("Token doesn't have a subject public key") if "issuer" not in decoded_token_payload: raise ValueError("Token doesn't have an issuer") if "publicKey" not in decoded_token_payload["issuer"]: raise ValueError("Token doesn't have an issuer public key") if "claim" not in decoded_token_payload: raise ValueError("Token doesn't have a claim") issuer_public_key = str(decoded_token_payload["issuer"]["publicKey"]) public_key_object = ECPublicKey(issuer_public_key) compressed_public_key = compress(issuer_public_key) decompressed_public_key = decompress(issuer_public_key) if public_key_object._type == PubkeyType.compressed: compressed_address = public_key_object.address() uncompressed_address = bin_hash160_to_address( bin_hash160( decompress(public_key_object.to_bin()) ) ) elif public_key_object._type == PubkeyType.uncompressed: compressed_address = bin_hash160_to_address( bin_hash160( compress(public_key_object.to_bin()) ) ) uncompressed_address = public_key_object.address() else: raise ValueError("Invalid issuer public key format") if public_key_or_address == compressed_public_key: pass elif public_key_or_address == decompressed_public_key: pass elif public_key_or_address == compressed_address: pass elif public_key_or_address == uncompressed_address: pass else: raise ValueError("Token public key doesn't match the verifying value") token_verifier = TokenVerifier() if not token_verifier.verify(token, public_key_object.to_pem()): raise ValueError("Token was not signed by the issuer public key") return decoded_token
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_translations'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '6', 'type': 'block', 'children': ['7', '16', '29', '33', '131', '144', '148']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'locale'},{'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': 'normalize_locale'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '16', 'type': 'if_statement', 'children': ['17', '22']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'in'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'translations'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'subscript', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'translations'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'translations'},{'id': '32', 'type': 'dictionary', 'children': []},{'id': '33', 'type': 'for_statement', 'children': ['34', '35', '38']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '38', 'type': 'block', 'children': ['39', '56', '68', '76', '84', '93', '101']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'file'},{'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': 'os'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'{}.py'"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '56', 'type': 'if_statement', 'children': ['57', '66']},{'id': '57', 'type': 'not_operator', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '64']},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'continue_statement', 'children': []},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'SourceFileLoader'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'locale_dict'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'load_module'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'if_statement', 'children': ['85', '91']},{'id': '85', 'type': 'not_operator', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'locale_dict'},{'id': '90', 'type': 'string', 'children': [], 'value': "'translations'"},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'continue_statement', 'children': []},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'locale_dict'},{'id': '100', 'type': 'string', 'children': [], 'value': "'translations'"},{'id': '101', 'type': 'if_statement', 'children': ['102', '103', '108']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'translations'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'translations'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '108', 'type': 'else_clause', 'children': ['109']},{'id': '109', 'type': 'block', 'children': ['110', '127']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'merged'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'binary_operator', 'children': ['117', '122'], 'value': '|'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'translations'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'translations'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'merged'},{'id': '131', 'type': 'if_statement', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'translations'},{'id': '133', 'type': 'block', 'children': ['134', '142']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '141']},{'id': '136', 'type': 'subscript', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'translations'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'translations'},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'translations'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '147', 'type': 'string', 'children': [], 'value': "'No translations found for locale [{}]'"},{'id': '148', 'type': 'raise_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'NoTranslations'},{'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': 'err'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'locale'}
def get_translations(self, locale): locale = self.normalize_locale(locale) if locale in self.translations: return self.translations[locale] translations = {} for path in self.dirs: file = os.path.join(path, '{}.py'.format(locale)) if not os.path.isfile(file): continue loader = SourceFileLoader(locale, file) locale_dict = loader.load_module() if not hasattr(locale_dict, 'translations'): continue language = getattr(locale_dict, 'translations') if translations: translations = language else: merged = dict(translations.items() | language.items()) translations = merged if translations: self.translations[locale] = translations return translations err = 'No translations found for locale [{}]' raise NoTranslations(err.format(locale))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_request'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '6', 'type': 'block', 'children': ['7', '15', '28', '236']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'debugger'},{'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': 'debugger'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '18', 'type': 'conditional_expression', 'children': ['19', '24', '27'], 'value': 'if'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'debugger'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'session_id'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'debugger'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'try_statement', 'children': ['29', '211']},{'id': '29', 'type': 'block', 'children': ['30', '38', '61', '197']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'read_request'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'debugger'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51', '56']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'protocol_version'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'protocol'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'try_statement', 'children': ['62', '150']},{'id': '62', 'type': 'block', 'children': ['63', '77', '90', '137']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'target_route'},{'id': '66', 'type': 'call', 'children': ['67', '74']},{'id': '67', 'type': 'attribute', 'children': ['68', '73']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'route_map'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'if_statement', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'is'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '80', 'type': 'None', 'children': []},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'debugger'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'target_route'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'target_route'},{'id': '90', 'type': 'if_statement', 'children': ['91', '94', '105']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'is'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'target_route'},{'id': '93', 'type': 'None', 'children': []},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'target_route'},{'id': '105', 'type': 'else_clause', 'children': ['106']},{'id': '106', 'type': 'block', 'children': ['107', '119', '126']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'presenter_cls'},{'id': '110', 'type': 'call', 'children': ['111', '118']},{'id': '111', 'type': 'attribute', 'children': ['112', '117']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'route_map'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'error_presenter'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'presenter'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'presenter_cls'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'presenter'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'error_code'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '136', 'type': 'integer', 'children': [], 'value': '404'},{'id': '137', 'type': 'if_statement', 'children': ['138', '141']},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': 'is'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '140', 'type': 'None', 'children': []},{'id': '141', 'type': 'block', 'children': ['142']},{'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': 'debugger'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '150', 'type': 'except_clause', 'children': ['151', '155']},{'id': '151', 'type': 'as_pattern', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '153', 'type': 'as_pattern_target', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '155', 'type': 'block', 'children': ['156', '169', '181', '188']},{'id': '156', 'type': 'if_statement', 'children': ['157', '160']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': 'is'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '159', 'type': 'None', 'children': []},{'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': 'debugger'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'presenter_cls'},{'id': '172', 'type': 'call', 'children': ['173', '180']},{'id': '173', 'type': 'attribute', 'children': ['174', '179']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'route_map'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'error_presenter'},{'id': '180', 'type': 'argument_list', 'children': []},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'presenter'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'presenter_cls'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'presenter'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'exception_error'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'e'},{'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': 'session'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'write_response'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204', '205']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '205', 'type': 'list_splat', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '209', 'type': 'identifier', 'children': [], 'value': '__pushed_responses__'},{'id': '210', 'type': 'argument_list', 'children': []},{'id': '211', 'type': 'except_clause', 'children': ['212', '216']},{'id': '212', 'type': 'as_pattern', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '214', 'type': 'as_pattern_target', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '216', 'type': 'block', 'children': ['217', '230']},{'id': '217', 'type': 'if_statement', 'children': ['218', '221']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'is'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '220', 'type': 'None', 'children': []},{'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': 'debugger'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'session_close'},{'id': '235', 'type': 'argument_list', 'children': []},{'id': '236', 'type': 'if_statement', 'children': ['237', '240']},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': 'is'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'},{'id': '239', 'type': 'None', 'children': []},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'debugger'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'finalize'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'debugger_session_id'}
def process_request(self, session): debugger = self.debugger() debugger_session_id = debugger.session_id() if debugger is not None else None try: request = session.read_request() if debugger_session_id is not None: debugger.request( debugger_session_id, request, session.protocol_version(), session.protocol() ) try: target_route = self.route_map().route(request, self) if debugger_session_id is not None: debugger.target_route(debugger_session_id, target_route) if target_route is not None: response = self.execute(request, target_route) else: presenter_cls = self.route_map().error_presenter() presenter = presenter_cls(request) response = presenter.error_code(code=404) if debugger_session_id is not None: debugger.response(debugger_session_id, response) except Exception as e: if debugger_session_id is not None: debugger.exception(debugger_session_id, e) presenter_cls = self.route_map().error_presenter() presenter = presenter_cls(request) response = presenter.exception_error(e) session.write_response(request, response, *response.__pushed_responses__()) except Exception as e: if debugger_session_id is not None: debugger.exception(debugger_session_id, e) session.session_close() if debugger_session_id is not None: debugger.finalize(debugger_session_id)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_point_in_section_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'point'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '6', 'type': 'block', 'children': ['7', '23', '65']},{'id': '7', 'type': 'if_statement', 'children': ['8', '20']},{'id': '8', 'type': 'boolean_operator', 'children': ['9', '14'], 'value': 'or'},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': '<'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'point'},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '>'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'point'},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '18', 'type': 'unary_operator', 'children': ['19'], 'value': '-'},{'id': '19', 'type': 'integer', 'children': [], 'value': '1'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'if_statement', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'in'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'point'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '27', 'type': 'block', 'children': ['28', '41', '52', '61']},{'id': '28', 'type': 'if_statement', 'children': ['29', '35']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '=='},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'point'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '33', 'type': 'unary_operator', 'children': ['34'], 'value': '-'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '39', 'type': 'unary_operator', 'children': ['40'], 'value': '-'},{'id': '40', 'type': 'integer', 'children': [], 'value': '2'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '51'], 'value': '-'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'bisect'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'point'},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'if_statement', 'children': ['53', '56']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '=='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '65', 'type': 'try_statement', 'children': ['66', '82']},{'id': '66', 'type': 'block', 'children': ['67', '76']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'bisect'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'point'},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '-'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'except_clause', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'None', 'children': []}
def find_point_in_section_list(point, section_list): if point < section_list[0] or point > section_list[-1]: return None if point in section_list: if point == section_list[-1]: return section_list[-2] ind = section_list.bisect(point)-1 if ind == 0: return section_list[0] return section_list[ind] try: ind = section_list.bisect(point) return section_list[ind-1] except IndexError: return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_range_ix_in_section_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '7', 'type': 'block', 'children': ['8', '26', '49', '74']},{'id': '8', 'type': 'if_statement', 'children': ['9', '21']},{'id': '9', 'type': 'boolean_operator', 'children': ['10', '16'], 'value': 'or'},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': '>'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '12', 'type': 'subscript', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '14', 'type': 'unary_operator', 'children': ['15'], 'value': '-'},{'id': '15', 'type': 'integer', 'children': [], 'value': '1'},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': '<'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'list', 'children': ['24', '25'], 'value': '[0, 0]'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'if_statement', 'children': ['27', '32', '39']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '<'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'start_section'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'else_clause', 'children': ['40']},{'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': 'start_section'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'find_point_in_section_list'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '49', 'type': 'if_statement', 'children': ['50', '56', '64']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': '>'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '54', 'type': 'unary_operator', 'children': ['55'], 'value': '-'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'end_section'},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '62', 'type': 'unary_operator', 'children': ['63'], 'value': '-'},{'id': '63', 'type': 'integer', 'children': [], 'value': '2'},{'id': '64', 'type': 'else_clause', 'children': ['65']},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'end_section'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'find_point_in_section_list'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'list', 'children': ['76', '82'], 'value': '[\n section_list.index(start_section), section_list.index(end_section)+1]'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'start_section'},{'id': '82', 'type': 'binary_operator', 'children': ['83', '89'], 'value': '+'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'end_section'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'}
def find_range_ix_in_section_list(start, end, section_list): if start > section_list[-1] or end < section_list[0]: return [0, 0] if start < section_list[0]: start_section = section_list[0] else: start_section = find_point_in_section_list(start, section_list) if end > section_list[-1]: end_section = section_list[-2] else: end_section = find_point_in_section_list(end, section_list) return [ section_list.index(start_section), section_list.index(end_section)+1]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_range_in_section_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '7', 'type': 'block', 'children': ['8', '17']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'find_range_ix_in_section_list'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'section_list'},{'id': '20', 'type': 'slice', 'children': ['21', '24', '25']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'colon', 'children': []},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'}
def find_range_in_section_list(start, end, section_list): ind = find_range_ix_in_section_list(start, end, section_list) return section_list[ind[0]: ind[1]]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_range_ix_in_point_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'point_list'},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'return_statement', 'children': ['9']},{'id': '9', 'type': 'list', 'children': ['10', '16'], 'value': '[point_list.bisect_left(start), point_list.bisect_right(end)]'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'point_list'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'bisect_left'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'point_list'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'bisect_right'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'end'}
def find_range_ix_in_point_list(start, end, point_list): return [point_list.bisect_left(start), point_list.bisect_right(end)]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'arg_name'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'decorated_function'},{'id': '8', 'type': 'block', 'children': ['9', '40']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'raise_exception'},{'id': '11', 'type': 'parameters', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'x_spec'},{'id': '13', 'type': 'block', 'children': ['14', '27', '35']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'exc_text'},{'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '%'},{'id': '18', 'type': 'string', 'children': [], 'value': '\'Argument "%s" for function "%s" has invalid type\''},{'id': '19', 'type': 'tuple', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'arg_name'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'Verifier'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'function_name'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'decorated_function'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'augmented_assignment', 'children': ['29', '30'], 'value': '+='},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'exc_text'},{'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '%'},{'id': '31', 'type': 'string', 'children': [], 'value': "' (%s should be %s)'"},{'id': '32', 'type': 'tuple', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x_spec'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '35', 'type': 'raise_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'exc_text'},{'id': '40', 'type': 'if_statement', 'children': ['41', '49', '155', '186']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '45', 'type': 'tuple', 'children': ['46', '47', '48']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '49', 'type': 'block', 'children': ['50', '72']},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'single_type'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'if_statement', 'children': ['55', '66']},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '60'], 'value': 'and'},{'id': '56', 'type': '()', 'children': ['57']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'single_type'},{'id': '59', 'type': 'None', 'children': []},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '65'], 'value': 'is'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'single_type'},{'id': '65', 'type': 'False', 'children': []},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'raise_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': "'Invalid specification. Must be type or tuple/list/set of types'"},{'id': '72', 'type': 'if_statement', 'children': ['73', '76', '125']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'in'},{'id': '74', 'type': 'None', 'children': []},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '76', 'type': 'block', 'children': ['77', '93']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '85', 'type': 'argument_list', 'children': ['86', '92']},{'id': '86', 'type': 'lambda', 'children': ['87', '89']},{'id': '87', 'type': 'lambda_parameters', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'is'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '91', 'type': 'None', 'children': []},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'lambda', 'children': ['95', '97']},{'id': '95', 'type': 'lambda_parameters', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '97', 'type': 'conditional_expression', 'children': ['98', '99', '113', '114'], 'value': 'if'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'boolean_operator', 'children': ['100', '103'], 'value': 'or'},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '102', 'type': 'None', 'children': []},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '112'], 'value': 'is'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '112', 'type': 'True', 'children': []},{'id': '113', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'raise_exception'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': '()', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '125', 'type': 'else_clause', 'children': ['126']},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'return_statement', 'children': ['128']},{'id': '128', 'type': 'lambda', 'children': ['129', '131']},{'id': '129', 'type': 'lambda_parameters', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '131', 'type': 'conditional_expression', 'children': ['132', '133', '143', '144'], 'value': 'if'},{'id': '132', 'type': 'None', 'children': []},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '142'], 'value': 'is'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '142', 'type': 'True', 'children': []},{'id': '143', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'raise_exception'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': '()', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '155', 'type': 'elif_clause', 'children': ['156', '160']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'return_statement', 'children': ['162']},{'id': '162', 'type': 'lambda', 'children': ['163', '165']},{'id': '163', 'type': 'lambda_parameters', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '165', 'type': 'conditional_expression', 'children': ['166', '167', '174', '175'], 'value': 'if'},{'id': '166', 'type': 'None', 'children': []},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '173'], 'value': 'is'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '173', 'type': 'True', 'children': []},{'id': '174', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'raise_exception'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': '()', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '186', 'type': 'else_clause', 'children': ['187']},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'raise_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'string', 'children': [], 'value': "'Invalid specification. Must be type or tuple/list/set of types'"}
def check(self, type_spec, arg_name, decorated_function): def raise_exception(x_spec): exc_text = 'Argument "%s" for function "%s" has invalid type' % ( arg_name, Verifier.function_name(decorated_function) ) exc_text += ' (%s should be %s)' % (x_spec, type_spec) raise TypeError(exc_text) if isinstance(type_spec, (tuple, list, set)): for single_type in type_spec: if (single_type is not None) and isclass(single_type) is False: raise RuntimeError( 'Invalid specification. Must be type or tuple/list/set of types' ) if None in type_spec: type_spec = tuple(filter(lambda x: x is not None, type_spec)) return lambda x: None if x is None or isinstance(x, tuple(type_spec)) is True else \ raise_exception(str((type(x)))) else: return lambda x: None if isinstance(x, tuple(type_spec)) is True else \ raise_exception(str((type(x)))) elif isclass(type_spec): return lambda x: None if isinstance(x, type_spec) is True else \ raise_exception(str((type(x)))) else: raise RuntimeError('Invalid specification. Must be type or tuple/list/set of types')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'arg_name'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'decorated_function'},{'id': '8', 'type': 'block', 'children': ['9', '38']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'raise_exception'},{'id': '11', 'type': 'parameters', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'text_spec'},{'id': '13', 'type': 'block', 'children': ['14', '27', '33']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'exc_text'},{'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '%'},{'id': '18', 'type': 'string', 'children': [], 'value': '\'Argument "%s" for function "%s" has invalid type\''},{'id': '19', 'type': 'tuple', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'arg_name'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'Verifier'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'function_name'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'decorated_function'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'augmented_assignment', 'children': ['29', '30'], 'value': '+='},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'exc_text'},{'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '%'},{'id': '31', 'type': 'string', 'children': [], 'value': "' (%s)'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'text_spec'},{'id': '33', 'type': 'raise_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'exc_text'},{'id': '38', 'type': 'if_statement', 'children': ['39', '47', '156', '191']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '43', 'type': 'tuple', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '47', 'type': 'block', 'children': ['48', '70']},{'id': '48', 'type': 'for_statement', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'single_type'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'if_statement', 'children': ['53', '64']},{'id': '53', 'type': 'boolean_operator', 'children': ['54', '58'], 'value': 'and'},{'id': '54', 'type': '()', 'children': ['55']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'single_type'},{'id': '57', 'type': 'None', 'children': []},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '63'], 'value': 'is'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'single_type'},{'id': '63', 'type': 'False', 'children': []},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'raise_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': "'Invalid specification. Must be type or tuple/list/set of types'"},{'id': '70', 'type': 'if_statement', 'children': ['71', '74', '125']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'in'},{'id': '72', 'type': 'None', 'children': []},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '74', 'type': 'block', 'children': ['75', '91']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '83', 'type': 'argument_list', 'children': ['84', '90']},{'id': '84', 'type': 'lambda', 'children': ['85', '87']},{'id': '85', 'type': 'lambda_parameters', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '89', 'type': 'None', 'children': []},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '91', 'type': 'return_statement', 'children': ['92']},{'id': '92', 'type': 'lambda', 'children': ['93', '95']},{'id': '93', 'type': 'lambda_parameters', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '95', 'type': 'conditional_expression', 'children': ['96', '97', '98', '117', '118'], 'value': 'if'},{'id': '96', 'type': 'None', 'children': []},{'id': '97', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '98', 'type': 'boolean_operator', 'children': ['99', '102'], 'value': 'or'},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '101', 'type': 'None', 'children': []},{'id': '102', 'type': '()', 'children': ['103']},{'id': '103', 'type': 'boolean_operator', 'children': ['104', '110'], 'value': 'and'},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '109'], 'value': 'is'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '109', 'type': 'True', 'children': []},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '116'], 'value': 'is'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '116', 'type': 'True', 'children': []},{'id': '117', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'raise_exception'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '125', 'type': 'else_clause', 'children': ['126']},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'return_statement', 'children': ['128']},{'id': '128', 'type': 'lambda', 'children': ['129', '131']},{'id': '129', 'type': 'lambda_parameters', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '131', 'type': 'conditional_expression', 'children': ['132', '133', '148', '149'], 'value': 'if'},{'id': '132', 'type': 'None', 'children': []},{'id': '133', 'type': '()', 'children': ['134']},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '141'], 'value': 'and'},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '140'], 'value': 'is'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '140', 'type': 'True', 'children': []},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '147'], 'value': 'is'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '147', 'type': 'True', 'children': []},{'id': '148', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'raise_exception'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '156', 'type': 'elif_clause', 'children': ['157', '161']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'return_statement', 'children': ['163']},{'id': '163', 'type': 'lambda', 'children': ['164', '166']},{'id': '164', 'type': 'lambda_parameters', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '166', 'type': 'conditional_expression', 'children': ['167', '168', '183', '184'], 'value': 'if'},{'id': '167', 'type': 'None', 'children': []},{'id': '168', 'type': '()', 'children': ['169']},{'id': '169', 'type': 'boolean_operator', 'children': ['170', '176'], 'value': 'and'},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '175'], 'value': 'is'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '175', 'type': 'True', 'children': []},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '182'], 'value': 'is'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '179', 'type': 'argument_list', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'type_spec'},{'id': '182', 'type': 'True', 'children': []},{'id': '183', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'raise_exception'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '191', 'type': 'else_clause', 'children': ['192']},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'raise_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'string', 'children': [], 'value': "'Invalid specification. Must be type or tuple/list/set of types'"}
def check(self, type_spec, arg_name, decorated_function): def raise_exception(text_spec): exc_text = 'Argument "%s" for function "%s" has invalid type' % ( arg_name, Verifier.function_name(decorated_function) ) exc_text += ' (%s)' % text_spec raise TypeError(exc_text) if isinstance(type_spec, (tuple, list, set)): for single_type in type_spec: if (single_type is not None) and isclass(single_type) is False: raise RuntimeError( 'Invalid specification. Must be type or tuple/list/set of types' ) if None in type_spec: type_spec = tuple(filter(lambda x: x is not None, type_spec)) return lambda x: None if \ x is None or (isclass(x) is True and issubclass(x, type_spec) is True) else \ raise_exception(str(x)) else: return lambda x: None if (isclass(x) is True and issubclass(x, type_spec) is True) else \ raise_exception(str(x)) elif isclass(type_spec): return lambda x: None if (isclass(x) is True and issubclass(x, type_spec) is True) else \ raise_exception(str(x)) else: raise RuntimeError('Invalid specification. Must be type or tuple/list/set of types')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'value_spec'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'arg_name'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'decorated_function'},{'id': '8', 'type': 'block', 'children': ['9', '38']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'raise_exception'},{'id': '11', 'type': 'parameters', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'text_spec'},{'id': '13', 'type': 'block', 'children': ['14', '27', '33']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'exc_text'},{'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '%'},{'id': '18', 'type': 'string', 'children': [], 'value': '\'Argument "%s" for function "%s" has invalid value\''},{'id': '19', 'type': 'tuple', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'arg_name'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'Verifier'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'function_name'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'decorated_function'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'augmented_assignment', 'children': ['29', '30'], 'value': '+='},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'exc_text'},{'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '%'},{'id': '31', 'type': 'string', 'children': [], 'value': "' (%s)'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'text_spec'},{'id': '33', 'type': 'raise_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'exc_text'},{'id': '38', 'type': 'if_statement', 'children': ['39', '47', '92', '117']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'value_spec'},{'id': '43', 'type': 'tuple', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '47', 'type': 'block', 'children': ['48', '65', '90']},{'id': '48', 'type': 'for_statement', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'single_value'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'value_spec'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'if_statement', 'children': ['53', '59']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '58'], 'value': 'is'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'isfunction'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'single_value'},{'id': '58', 'type': 'False', 'children': []},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'raise_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': "'Invalid specification. Must be function or tuple/list/set of functions'"},{'id': '65', 'type': 'function_definition', 'children': ['66', '67', '69']},{'id': '66', 'type': 'function_name', 'children': [], 'value': 'check'},{'id': '67', 'type': 'parameters', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '73']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'value_spec'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'if_statement', 'children': ['75', '81']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '80'], 'value': 'is'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '80', 'type': 'True', 'children': []},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'raise_exception'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '92', 'type': 'elif_clause', 'children': ['93', '97']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'isfunction'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'value_spec'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'lambda', 'children': ['100', '102']},{'id': '100', 'type': 'lambda_parameters', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '102', 'type': 'conditional_expression', 'children': ['103', '104', '110'], 'value': 'if'},{'id': '103', 'type': 'None', 'children': []},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '109'], 'value': 'is'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'value_spec'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '109', 'type': 'True', 'children': []},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'raise_exception'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '117', 'type': 'else_clause', 'children': ['118']},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'raise_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': "'Invalid specification. Must be function or tuple/list/set of functions'"}
def check(self, value_spec, arg_name, decorated_function): def raise_exception(text_spec): exc_text = 'Argument "%s" for function "%s" has invalid value' % ( arg_name, Verifier.function_name(decorated_function) ) exc_text += ' (%s)' % text_spec raise ValueError(exc_text) if isinstance(value_spec, (tuple, list, set)): for single_value in value_spec: if isfunction(single_value) is False: raise RuntimeError( 'Invalid specification. Must be function or tuple/list/set of functions' ) def check(x): for f in value_spec: if f(x) is not True: raise_exception(str(x)) return check elif isfunction(value_spec): return lambda x: None if value_spec(x) is True else raise_exception(str(x)) else: raise RuntimeError('Invalid specification. Must be function or tuple/list/set of functions')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cache_control'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '21', '30', '41', '128']},{'id': '11', 'type': 'function_definition', 'children': ['12', '13', '18']},{'id': '12', 'type': 'function_name', 'children': [], 'value': 'default_validator'},{'id': '13', 'type': 'parameters', 'children': ['14', '16']},{'id': '14', 'type': 'list_splat_pattern', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '16', 'type': 'dictionary_splat_pattern', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'True', 'children': []},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'default_validator'},{'id': '30', 'type': 'if_statement', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'WGlobalSingletonCacheStorage'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'function_definition', 'children': ['42', '43', '45']},{'id': '42', 'type': 'function_name', 'children': [], 'value': 'first_level_decorator'},{'id': '43', 'type': 'parameters', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'decorated_function'},{'id': '45', 'type': 'block', 'children': ['46', '120']},{'id': '46', 'type': 'function_definition', 'children': ['47', '48', '54']},{'id': '47', 'type': 'function_name', 'children': [], 'value': 'second_level_decorator'},{'id': '48', 'type': 'parameters', 'children': ['49', '50', '52']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'original_function'},{'id': '50', 'type': 'list_splat_pattern', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '52', 'type': 'dictionary_splat_pattern', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '54', 'type': 'block', 'children': ['55', '66', '79']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'validator_check'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62', '64']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'original_function'},{'id': '62', 'type': 'list_splat', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '64', 'type': 'dictionary_splat', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'cache_entry'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'get_cache'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '77']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'original_function'},{'id': '75', 'type': 'list_splat', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '77', 'type': 'dictionary_splat', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '79', 'type': 'if_statement', 'children': ['80', '89', '114']},{'id': '80', 'type': 'boolean_operator', 'children': ['81', '84'], 'value': 'or'},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'is'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'validator_check'},{'id': '83', 'type': 'True', 'children': []},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '88'], 'value': 'is'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'cache_entry'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'has_value'},{'id': '88', 'type': 'False', 'children': []},{'id': '89', 'type': 'block', 'children': ['90', '100', '112']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'original_function'},{'id': '95', 'type': 'argument_list', 'children': ['96', '98']},{'id': '96', 'type': 'list_splat', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '98', 'type': 'dictionary_splat', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'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': 'storage'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'put'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107', '108', '110']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'original_function'},{'id': '108', 'type': 'list_splat', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '110', 'type': 'dictionary_splat', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '112', 'type': 'return_statement', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '114', 'type': 'else_clause', 'children': ['115']},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'return_statement', 'children': ['117']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'cache_entry'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'cached_value'},{'id': '120', 'type': 'return_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '126']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'decorator'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'second_level_decorator'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'decorated_function'},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'first_level_decorator'}
def cache_control(validator=None, storage=None): def default_validator(*args, **kwargs): return True if validator is None: validator = default_validator if storage is None: storage = WGlobalSingletonCacheStorage() def first_level_decorator(decorated_function): def second_level_decorator(original_function, *args, **kwargs): validator_check = validator(original_function, *args, **kwargs) cache_entry = storage.get_cache(original_function, *args, **kwargs) if validator_check is not True or cache_entry.has_value is False: result = original_function(*args, **kwargs) storage.put(result, original_function, *args, **kwargs) return result else: return cache_entry.cached_value return decorator(second_level_decorator)(decorated_function) return first_level_decorator
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_int_string'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'int_string'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '8', 'type': 'type', 'children': ['9']},{'id': '9', 'type': 'generic_type', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '11', 'type': 'type_parameter', 'children': ['12']},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '14', 'type': 'block', 'children': ['15', '32', '42', '52', '61', '73', '168']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'cleaned'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': '" "'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '31']},{'id': '24', 'type': 'attribute', 'children': ['25', '30']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'int_string'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'cleaned'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'cleaned'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': '" - "'},{'id': '41', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'cleaned'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'cleaned'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': '","'},{'id': '51', 'type': 'string', 'children': [], 'value': '" "'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'cleaned'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'string', 'children': [], 'value': '" "'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64', '70']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '64', 'type': 'type', 'children': ['65']},{'id': '65', 'type': 'generic_type', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'Set'},{'id': '67', 'type': 'type_parameter', 'children': ['68']},{'id': '68', 'type': 'type', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'if_statement', 'children': ['78', '81', '144']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'in'},{'id': '79', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '81', 'type': 'block', 'children': ['82', '91', '107', '116', '127']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '91', 'type': 'if_statement', 'children': ['92', '98']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '97'], 'value': '!='},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '97', 'type': 'integer', 'children': [], 'value': '2'},{'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': 'LOG'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'string', 'children': [], 'value': 'f"Dropping \'{token}\' as invalid - weird range."'},{'id': '106', 'type': 'continue_statement', 'children': []},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '115', 'type': 'integer', 'children': [], 'value': '0'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '126'], 'value': '+'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '125', 'type': 'integer', 'children': [], 'value': '1'},{'id': '126', 'type': 'integer', 'children': [], 'value': '1'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '144', 'type': 'else_clause', 'children': ['145']},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'try_statement', 'children': ['147', '158']},{'id': '147', 'type': 'block', 'children': ['148']},{'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': 'indices'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '158', 'type': 'except_clause', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'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': 'LOG'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': 'f"Dropping \'{token}\' as invalid - not an int."'},{'id': '168', 'type': 'return_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'indices'}
def parse_int_string(int_string: str) -> List[int]: cleaned = " ".join(int_string.strip().split()) cleaned = cleaned.replace(" - ", "-") cleaned = cleaned.replace(",", " ") tokens = cleaned.split(" ") indices: Set[int] = set() for token in tokens: if "-" in token: endpoints = token.split("-") if len(endpoints) != 2: LOG.info(f"Dropping '{token}' as invalid - weird range.") continue start = int(endpoints[0]) end = int(endpoints[1]) + 1 indices = indices.union(indices, set(range(start, end))) else: try: indices.add(int(token)) except ValueError: LOG.info(f"Dropping '{token}' as invalid - not an int.") return list(indices)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'locations_within'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tolerance'},{'id': '7', 'type': 'block', 'children': ['8', '12', '19', '82', '101']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '11', 'type': 'string', 'children': [], 'value': "''"},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '19', 'type': 'for_statement', 'children': ['20', '23', '28']},{'id': '20', 'type': 'tuple_pattern', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'block', 'children': ['29', '41', '78']},{'id': '29', 'type': 'if_statement', 'children': ['30', '33']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'not'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'raise_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'binary_operator', 'children': ['39', '40'], 'value': '+'},{'id': '39', 'type': 'string', 'children': [], 'value': '"b does not have the key: "'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '41', 'type': 'if_statement', 'children': ['42', '58']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '57'], 'value': '>'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'binary_operator', 'children': ['47', '51'], 'value': '-'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'tolerance'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'augmented_assignment', 'children': ['61', '62'], 'value': '+='},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': "'key {0} differs: {1} {2}'"},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68', '72']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'delete_statement', 'children': ['79']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '82', 'type': 'if_statement', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'raise_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '+'},{'id': '90', 'type': 'string', 'children': [], 'value': '"keys in b not seen in a: "'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': '", "'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'return_statement', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ret'}
def locations_within(a, b, tolerance): ret = '' b = dict(b) for (key, value) in a.items(): if key not in b: raise ValueError("b does not have the key: " + key) if abs(int(value) - int(b[key])) > tolerance: ret += 'key {0} differs: {1} {2}'.format(key, int(value), int(b[key])) del b[key] if b: raise ValueError("keys in b not seen in a: " + ", ".join(b.keys())) return ret
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'persistence2stats'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'rev_docs'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'min_persisted'},{'id': '7', 'type': 'integer', 'children': [], 'value': '5'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'min_visible'},{'id': '10', 'type': 'integer', 'children': [], 'value': '1209600'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '32', '39', '46', '58', '70']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'rev_docs'},{'id': '24', 'type': 'call', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'mwxml'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'utilities'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'rev_docs'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'min_persisted'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'min_persisted'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'min_visible'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'min_visible'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '49', 'type': 'conditional_expression', 'children': ['50', '51', '54'], 'value': 'if'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'lambda', 'children': ['55', '57']},{'id': '55', 'type': 'lambda_parameters', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '57', 'type': 'True', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '61', 'type': 'conditional_expression', 'children': ['62', '63', '66'], 'value': 'if'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '65', 'type': 'None', 'children': []},{'id': '66', 'type': 'lambda', 'children': ['67', '69']},{'id': '67', 'type': 'lambda_parameters', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '69', 'type': 'False', 'children': []},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '73']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'rev_doc'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'rev_docs'},{'id': '73', 'type': 'block', 'children': ['74', '80', '108', '133', '294', '314', '323']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'persistence_doc'},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'rev_doc'},{'id': '79', 'type': 'string', 'children': [], 'value': "'persistence'"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '83', 'type': 'dictionary', 'children': ['84', '87', '90', '93', '96', '99', '102', '105']},{'id': '84', 'type': 'pair', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': "'tokens_added'"},{'id': '86', 'type': 'integer', 'children': [], 'value': '0'},{'id': '87', 'type': 'pair', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'persistent_tokens'"},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'pair', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': "'non_self_persistent_tokens'"},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'pair', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "'sum_log_persisted'"},{'id': '95', 'type': 'integer', 'children': [], 'value': '0'},{'id': '96', 'type': 'pair', 'children': ['97', '98']},{'id': '97', 'type': 'string', 'children': [], 'value': "'sum_log_non_self_persisted'"},{'id': '98', 'type': 'integer', 'children': [], 'value': '0'},{'id': '99', 'type': 'pair', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': "'sum_log_seconds_visible'"},{'id': '101', 'type': 'integer', 'children': [], 'value': '0'},{'id': '102', 'type': 'pair', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': "'censored'"},{'id': '104', 'type': 'False', 'children': []},{'id': '105', 'type': 'pair', 'children': ['106', '107']},{'id': '106', 'type': 'string', 'children': [], 'value': "'non_self_censored'"},{'id': '107', 'type': 'False', 'children': []},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'filtered_docs'},{'id': '111', 'type': 'generator_expression', 'children': ['112', '113', '118']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'persistence_doc'},{'id': '117', 'type': 'string', 'children': [], 'value': "'tokens'"},{'id': '118', 'type': 'if_clause', 'children': ['119']},{'id': '119', 'type': 'boolean_operator', 'children': ['120', '126'], 'value': 'and'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '125', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '126', 'type': 'not_operator', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '132', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '133', 'type': 'for_statement', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'token_doc'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'filtered_docs'},{'id': '136', 'type': 'block', 'children': ['137', '157', '163', '176', '190', '204']},{'id': '137', 'type': 'if_statement', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '139', 'type': 'block', 'children': ['140', '149']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '147']},{'id': '142', 'type': 'attribute', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'string', 'children': [], 'value': '"."'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '156']},{'id': '151', 'type': 'attribute', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '156', 'type': 'argument_list', 'children': []},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'augmented_assignment', 'children': ['159', '162'], 'value': '+='},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '161', 'type': 'string', 'children': [], 'value': "'tokens_added'"},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'augmented_assignment', 'children': ['165', '168'], 'value': '+='},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '167', 'type': 'string', 'children': [], 'value': "'sum_log_persisted'"},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'binary_operator', 'children': ['172', '175'], 'value': '+'},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'token_doc'},{'id': '174', 'type': 'string', 'children': [], 'value': "'persisted'"},{'id': '175', 'type': 'integer', 'children': [], 'value': '1'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'augmented_assignment', 'children': ['178', '181', '182'], 'value': '+='},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '180', 'type': 'string', 'children': [], 'value': "'sum_log_non_self_persisted'"},{'id': '181', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'binary_operator', 'children': ['186', '189'], 'value': '+'},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'token_doc'},{'id': '188', 'type': 'string', 'children': [], 'value': "'non_self_persisted'"},{'id': '189', 'type': 'integer', 'children': [], 'value': '1'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'augmented_assignment', 'children': ['192', '195', '196'], 'value': '+='},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '194', 'type': 'string', 'children': [], 'value': "'sum_log_seconds_visible'"},{'id': '195', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'binary_operator', 'children': ['200', '203'], 'value': '+'},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'token_doc'},{'id': '202', 'type': 'string', 'children': [], 'value': "'seconds_visible'"},{'id': '203', 'type': 'integer', 'children': [], 'value': '1'},{'id': '204', 'type': 'if_statement', 'children': ['205', '210', '223']},{'id': '205', 'type': 'comparison_operator', 'children': ['206', '209'], 'value': '>='},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'token_doc'},{'id': '208', 'type': 'string', 'children': [], 'value': "'seconds_visible'"},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'min_visible'},{'id': '210', 'type': 'block', 'children': ['211', '217']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'augmented_assignment', 'children': ['213', '216'], 'value': '+='},{'id': '213', 'type': 'subscript', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '215', 'type': 'string', 'children': [], 'value': "'persistent_tokens'"},{'id': '216', 'type': 'integer', 'children': [], 'value': '1'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'augmented_assignment', 'children': ['219', '222'], 'value': '+='},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '221', 'type': 'string', 'children': [], 'value': "'non_self_persistent_tokens'"},{'id': '222', 'type': 'integer', 'children': [], 'value': '1'},{'id': '223', 'type': 'else_clause', 'children': ['224']},{'id': '224', 'type': 'block', 'children': ['225', '236', '247']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'augmented_assignment', 'children': ['227', '230', '231'], 'value': '+='},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '229', 'type': 'string', 'children': [], 'value': "'persistent_tokens'"},{'id': '230', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '235'], 'value': '>='},{'id': '232', 'type': 'subscript', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'token_doc'},{'id': '234', 'type': 'string', 'children': [], 'value': "'persisted'"},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'min_persisted'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'augmented_assignment', 'children': ['238', '241', '242'], 'value': '+='},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '240', 'type': 'string', 'children': [], 'value': "'non_self_persistent_tokens'"},{'id': '241', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '246'], 'value': '>='},{'id': '243', 'type': 'subscript', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'token_doc'},{'id': '245', 'type': 'string', 'children': [], 'value': "'non_self_persisted'"},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'min_persisted'},{'id': '247', 'type': 'if_statement', 'children': ['248', '253', '266']},{'id': '248', 'type': 'comparison_operator', 'children': ['249', '252'], 'value': '<'},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'persistence_doc'},{'id': '251', 'type': 'string', 'children': [], 'value': "'seconds_possible'"},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'min_visible'},{'id': '253', 'type': 'block', 'children': ['254', '260']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '259']},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '258', 'type': 'string', 'children': [], 'value': "'censored'"},{'id': '259', 'type': 'True', 'children': []},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '265']},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '264', 'type': 'string', 'children': [], 'value': "'non_self_censored'"},{'id': '265', 'type': 'True', 'children': []},{'id': '266', 'type': 'else_clause', 'children': ['267']},{'id': '267', 'type': 'block', 'children': ['268', '281']},{'id': '268', 'type': 'if_statement', 'children': ['269', '274']},{'id': '269', 'type': 'comparison_operator', 'children': ['270', '273'], 'value': '<'},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'persistence_doc'},{'id': '272', 'type': 'string', 'children': [], 'value': "'revisions_processed'"},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'min_persisted'},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '280']},{'id': '277', 'type': 'subscript', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '279', 'type': 'string', 'children': [], 'value': "'censored'"},{'id': '280', 'type': 'True', 'children': []},{'id': '281', 'type': 'if_statement', 'children': ['282', '287']},{'id': '282', 'type': 'comparison_operator', 'children': ['283', '286'], 'value': '<'},{'id': '283', 'type': 'subscript', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'persistence_doc'},{'id': '285', 'type': 'string', 'children': [], 'value': "'non_self_processed'"},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'min_persisted'},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '293']},{'id': '290', 'type': 'subscript', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '292', 'type': 'string', 'children': [], 'value': "'non_self_censored'"},{'id': '293', 'type': 'True', 'children': []},{'id': '294', 'type': 'if_statement', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '296', 'type': 'block', 'children': ['297', '306']},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '304']},{'id': '299', 'type': 'attribute', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '313']},{'id': '308', 'type': 'attribute', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '313', 'type': 'argument_list', 'children': []},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '321']},{'id': '316', 'type': 'attribute', 'children': ['317', '320']},{'id': '317', 'type': 'subscript', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'rev_doc'},{'id': '319', 'type': 'string', 'children': [], 'value': "'persistence'"},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'stats_doc'},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'yield', 'children': ['325']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'rev_doc'}
def persistence2stats(rev_docs, min_persisted=5, min_visible=1209600, include=None, exclude=None, verbose=False): rev_docs = mwxml.utilities.normalize(rev_docs) min_persisted = int(min_persisted) min_visible = int(min_visible) include = include if include is not None else lambda t: True exclude = exclude if exclude is not None else lambda t: False for rev_doc in rev_docs: persistence_doc = rev_doc['persistence'] stats_doc = { 'tokens_added': 0, 'persistent_tokens': 0, 'non_self_persistent_tokens': 0, 'sum_log_persisted': 0, 'sum_log_non_self_persisted': 0, 'sum_log_seconds_visible': 0, 'censored': False, 'non_self_censored': False } filtered_docs = (t for t in persistence_doc['tokens'] if include(t['text']) and not exclude(t['text'])) for token_doc in filtered_docs: if verbose: sys.stderr.write(".") sys.stderr.flush() stats_doc['tokens_added'] += 1 stats_doc['sum_log_persisted'] += log(token_doc['persisted'] + 1) stats_doc['sum_log_non_self_persisted'] += \ log(token_doc['non_self_persisted'] + 1) stats_doc['sum_log_seconds_visible'] += \ log(token_doc['seconds_visible'] + 1) if token_doc['seconds_visible'] >= min_visible: stats_doc['persistent_tokens'] += 1 stats_doc['non_self_persistent_tokens'] += 1 else: stats_doc['persistent_tokens'] += \ token_doc['persisted'] >= min_persisted stats_doc['non_self_persistent_tokens'] += \ token_doc['non_self_persisted'] >= min_persisted if persistence_doc['seconds_possible'] < min_visible: stats_doc['censored'] = True stats_doc['non_self_censored'] = True else: if persistence_doc['revisions_processed'] < min_persisted: stats_doc['censored'] = True if persistence_doc['non_self_processed'] < min_persisted: stats_doc['non_self_censored'] = True if verbose: sys.stderr.write("\n") sys.stderr.flush() rev_doc['persistence'].update(stats_doc) yield rev_doc
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_index'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '106', '112', '116', '185', '207', '213']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'for_statement', 'children': ['11', '14', '35']},{'id': '11', 'type': 'pattern_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '16', 'type': 'argument_list', 'children': ['17', '24']},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'permissions'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '26', 'type': 'lambda', 'children': ['27', '29']},{'id': '27', 'type': 'lambda_parameters', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'block', 'children': ['36', '40', '46', '92', '100']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'branch'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'parent_p'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'const'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'PERM_DENY'},{'id': '46', 'type': 'for_statement', 'children': ['47', '48', '53']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '53', 'type': 'block', 'children': ['54', '80', '86']},{'id': '54', 'type': 'if_statement', 'children': ['55', '59']},{'id': '55', 'type': 'not_operator', 'children': ['56']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'branch'},{'id': '59', 'type': 'block', 'children': ['60', '69']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '65']},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'branch'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '65', 'type': 'dictionary', 'children': ['66']},{'id': '66', 'type': 'pair', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': '"__"'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'parent_p'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'branch'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': '__implicit'},{'id': '79', 'type': 'True', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'branch'},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'branch'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'parent_p'},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'branch'},{'id': '91', 'type': 'string', 'children': [], 'value': '"__"'},{'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': 'branch'},{'id': '96', 'type': 'string', 'children': [], 'value': '"__"'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'branch'},{'id': '104', 'type': 'string', 'children': [], 'value': '"__implicit"'},{'id': '105', 'type': 'False', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ramap'},{'id': '115', 'type': 'dictionary', 'children': []},{'id': '116', 'type': 'function_definition', 'children': ['117', '118', '120']},{'id': '117', 'type': 'function_name', 'children': [], 'value': 'update_ramap'},{'id': '118', 'type': 'parameters', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'branch_idx'},{'id': '120', 'type': 'block', 'children': ['121', '128', '159', '183']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '124', 'type': 'dictionary', 'children': ['125']},{'id': '125', 'type': 'pair', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': '"__"'},{'id': '127', 'type': 'False', 'children': []},{'id': '128', 'type': 'for_statement', 'children': ['129', '132', '140']},{'id': '129', 'type': 'pattern_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'branch_idx'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '139', 'type': 'argument_list', 'children': []},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'if_statement', 'children': ['142', '149']},{'id': '142', 'type': 'boolean_operator', 'children': ['143', '146'], 'value': 'and'},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': '!='},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '145', 'type': 'string', 'children': [], 'value': '"__"'},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '!='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '148', 'type': 'string', 'children': [], 'value': '"__implicit"'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'update_ramap'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '159', 'type': 'if_statement', 'children': ['160', '176']},{'id': '160', 'type': 'boolean_operator', 'children': ['161', '166'], 'value': 'and'},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '165'], 'value': 'is'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'branch_idx'},{'id': '164', 'type': 'string', 'children': [], 'value': '"__"'},{'id': '165', 'type': 'None', 'children': []},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '175'], 'value': '!='},{'id': '167', 'type': '()', 'children': ['168']},{'id': '168', 'type': 'binary_operator', 'children': ['169', '172'], 'value': '&'},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'branch_idx'},{'id': '171', 'type': 'string', 'children': [], 'value': '"__"'},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'const'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'PERM_READ'},{'id': '175', 'type': 'integer', 'children': [], 'value': '0'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '182']},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '181', 'type': 'string', 'children': [], 'value': '"__"'},{'id': '182', 'type': 'True', 'children': []},{'id': '183', 'type': 'return_statement', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '185', 'type': 'for_statement', 'children': ['186', '189', '197']},{'id': '186', 'type': 'pattern_list', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '196', 'type': 'argument_list', 'children': []},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '203']},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'ramap'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'update_ramap'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'read_access_map'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'ramap'},{'id': '213', 'type': 'return_statement', 'children': ['214']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'index'}
def update_index(self): idx = {} for _, p in sorted(self.permissions.items(), key=lambda x: str(x[0])): branch = idx parent_p = const.PERM_DENY for k in p.namespace.keys: if not k in branch: branch[k] = {"__": parent_p} branch[k].update(__implicit=True) branch = branch[k] parent_p = branch["__"] branch["__"] = p.value branch["__implicit"] = False self.index = idx ramap = {} def update_ramap(branch_idx): r = {"__": False} for k, v in list(branch_idx.items()): if k != "__" and k != "__implicit": r[k] = update_ramap(v) if branch_idx["__"] is not None and (branch_idx["__"] & const.PERM_READ) != 0: r["__"] = True return r for k, v in list(idx.items()): ramap[k] = update_ramap(v) self.read_access_map = ramap return self.index
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'type_check'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'func_handle'},{'id': '5', 'type': 'block', 'children': ['6', '101', '310']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '12']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'checkType'},{'id': '8', 'type': 'parameters', 'children': ['9', '10', '11']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'var_name'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'var_val'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'annot'},{'id': '12', 'type': 'block', 'children': ['13', '78']},{'id': '13', 'type': 'if_statement', 'children': ['14', '17', '68']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'in'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'var_name'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'annot'},{'id': '17', 'type': 'block', 'children': ['18', '24']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'var_anno'},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'annot'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'var_name'},{'id': '24', 'type': 'if_statement', 'children': ['25', '28', '33', '52']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'var_val'},{'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': 'type_ok'},{'id': '32', 'type': 'True', 'children': []},{'id': '33', 'type': 'elif_clause', 'children': ['34', '41']},{'id': '34', 'type': '()', 'children': ['35']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '40'], 'value': 'is'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'var_val'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'type_ok'},{'id': '45', 'type': '()', 'children': ['46']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '51'], 'value': 'in'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'var_val'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'var_anno'},{'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': 'type_ok'},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'in'},{'id': '58', 'type': 'True', 'children': []},{'id': '59', 'type': 'list_comprehension', 'children': ['60', '65']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'var_val'},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'var_anno'},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70', '74']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'var_anno'},{'id': '73', 'type': 'string', 'children': [], 'value': "'Unspecified'"},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'type_ok'},{'id': '77', 'type': 'True', 'children': []},{'id': '78', 'type': 'if_statement', 'children': ['79', '81']},{'id': '79', 'type': 'not_operator', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'type_ok'},{'id': '81', 'type': 'block', 'children': ['82', '95']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '85', 'type': 'tuple', 'children': ['86', '87', '90', '91']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'var_name'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'func_handle'},{'id': '89', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'var_anno'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'var_val'},{'id': '95', 'type': 'raise_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'QtmacsArgumentError'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'list_splat', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '101', 'type': 'decorated_definition', 'children': ['102', '109']},{'id': '102', 'type': 'decorator', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'wraps'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'func_handle'},{'id': '109', 'type': 'function_definition', 'children': ['110', '111', '116']},{'id': '110', 'type': 'function_name', 'children': [], 'value': 'wrapper'},{'id': '111', 'type': 'parameters', 'children': ['112', '114']},{'id': '112', 'type': 'list_splat_pattern', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '114', 'type': 'dictionary_splat_pattern', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '116', 'type': 'block', 'children': ['117', '126', '130', '170', '224', '231', '259', '302']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'getfullargspec'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'func_handle'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'annot'},{'id': '129', 'type': 'dictionary', 'children': []},{'id': '130', 'type': 'for_statement', 'children': ['131', '134', '141']},{'id': '131', 'type': 'pattern_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '140', 'type': 'argument_list', 'children': []},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'if_statement', 'children': ['143', '154', '161']},{'id': '143', 'type': 'boolean_operator', 'children': ['144', '149'], 'value': 'or'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '160']},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'annot'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '161', 'type': 'else_clause', 'children': ['162']},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '168']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'annot'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '168', 'type': 'expression_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '170', 'type': 'if_statement', 'children': ['171', '176', '192']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '175'], 'value': 'is'},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '175', 'type': 'None', 'children': []},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'binary_operator', 'children': ['184', '186'], 'value': '*'},{'id': '184', 'type': 'list', 'children': ['185'], 'value': '[None]'},{'id': '185', 'type': 'None', 'children': []},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '192', 'type': 'else_clause', 'children': ['193']},{'id': '193', 'type': 'block', 'children': ['194', '210']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'num_none'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '204'], 'value': '-'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '213', 'type': 'binary_operator', 'children': ['214', '221'], 'value': '+'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'binary_operator', 'children': ['218', '220'], 'value': '*'},{'id': '218', 'type': 'list', 'children': ['219'], 'value': '[None]'},{'id': '219', 'type': 'None', 'children': []},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'num_none'},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'ofs'},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '231', 'type': 'for_statement', 'children': ['232', '235', '245']},{'id': '232', 'type': 'pattern_list', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'var_name'},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'subscript', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '242', 'type': 'slice', 'children': ['243', '244']},{'id': '243', 'type': 'colon', 'children': []},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'ofs'},{'id': '245', 'type': 'block', 'children': ['246', '252']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'var_val'},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'checkType'},{'id': '255', 'type': 'argument_list', 'children': ['256', '257', '258']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'var_name'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'var_val'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'annot'},{'id': '259', 'type': 'for_statement', 'children': ['260', '263', '273']},{'id': '260', 'type': 'pattern_list', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'var_name'},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'subscript', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'argspec'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '270', 'type': 'slice', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'ofs'},{'id': '272', 'type': 'colon', 'children': []},{'id': '273', 'type': 'block', 'children': ['274', '295']},{'id': '274', 'type': 'if_statement', 'children': ['275', '278', '285']},{'id': '275', 'type': 'comparison_operator', 'children': ['276', '277'], 'value': 'in'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'var_name'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '278', 'type': 'block', 'children': ['279']},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'assignment', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'var_val'},{'id': '282', 'type': 'subscript', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'var_name'},{'id': '285', 'type': 'else_clause', 'children': ['286']},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'var_val'},{'id': '290', 'type': 'subscript', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '292', 'type': 'binary_operator', 'children': ['293', '294'], 'value': '+'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'ofs'},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'checkType'},{'id': '298', 'type': 'argument_list', 'children': ['299', '300', '301']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'var_name'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'var_val'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'annot'},{'id': '302', 'type': 'return_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'func_handle'},{'id': '305', 'type': 'argument_list', 'children': ['306', '308']},{'id': '306', 'type': 'list_splat', 'children': ['307']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '308', 'type': 'dictionary_splat', 'children': ['309']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '310', 'type': 'return_statement', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'wrapper'}
def type_check(func_handle): def checkType(var_name, var_val, annot): if var_name in annot: var_anno = annot[var_name] if var_val is None: type_ok = True elif (type(var_val) is bool): type_ok = (type(var_val) in var_anno) else: type_ok = True in [isinstance(var_val, _) for _ in var_anno] else: var_anno = 'Unspecified' type_ok = True if not type_ok: args = (var_name, func_handle.__name__, var_anno, type(var_val)) raise QtmacsArgumentError(*args) @functools.wraps(func_handle) def wrapper(*args, **kwds): argspec = inspect.getfullargspec(func_handle) annot = {} for key, val in argspec.annotations.items(): if isinstance(val, tuple) or isinstance(val, list): annot[key] = val else: annot[key] = val, if argspec.defaults is None: defaults = tuple([None] * len(argspec.args)) else: num_none = len(argspec.args) - len(argspec.defaults) defaults = tuple([None] * num_none) + argspec.defaults ofs = len(args) for idx, var_name in enumerate(argspec.args[:ofs]): var_val = args[idx] checkType(var_name, var_val, annot) for idx, var_name in enumerate(argspec.args[ofs:]): if var_name in kwds: var_val = kwds[var_name] else: var_val = defaults[idx + ofs] checkType(var_name, var_val, annot) return func_handle(*args, **kwds) return wrapper
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteProcessKey'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'targetObj'},{'id': '7', 'type': 'block', 'children': ['8', '18', '25', '36', '72', '81', '89', '120', '133', '142', '337', '348', '355', '366']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'QtmacsMessage'},{'id': '13', 'type': 'argument_list', 'children': ['14', '17']},{'id': '14', 'type': 'tuple', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'targetObj'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'setSignalName'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': "'qtesigKeypressed'"},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '34']},{'id': '27', 'type': 'attribute', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'qteMain'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'qtesigKeypressed'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '36', 'type': 'if_statement', 'children': ['37', '69']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '43'], 'value': 'in'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'tuple', 'children': ['44', '49', '54', '59', '64']},{'id': '44', 'type': 'attribute', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'Key_Shift'},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'Key_Control'},{'id': '54', 'type': 'attribute', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'Key_Meta'},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'Key_Alt'},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'QtCore'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'Qt'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'Key_AltGr'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'False', 'children': []},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '79']},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_keysequence'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'appendQKeyEvent'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'isRegisteredWidget'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'targetObj'},{'id': '88', 'type': 'string', 'children': [], 'value': "'_qteAdmin'"},{'id': '89', 'type': 'if_statement', 'children': ['90', '99', '108']},{'id': '90', 'type': 'boolean_operator', 'children': ['91', '92'], 'value': 'and'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'isRegisteredWidget'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '94', 'type': 'argument_list', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'targetObj'},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'},{'id': '98', 'type': 'string', 'children': [], 'value': "'keyMap'"},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'keyMap'},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'targetObj'},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'keyMap'},{'id': '108', 'type': 'else_clause', 'children': ['109']},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'keyMap'},{'id': '113', 'type': 'call', 'children': ['114', '119']},{'id': '114', 'type': 'attribute', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'qteMain'},{'id': '118', 'type': 'identifier', 'children': [], 'value': '_qteGlobalKeyMapByReference'},{'id': '119', 'type': 'argument_list', 'children': []},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '125']},{'id': '122', 'type': 'tuple_pattern', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'macroName'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'isPartialMatch'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'keyMap'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_keysequence'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'keyseq_copy'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'QtmacsKeysequence'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_keysequence'},{'id': '142', 'type': 'if_statement', 'children': ['143', '144', '230']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'isPartialMatch'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'if_statement', 'children': ['146', '149', '176']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': 'is'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'macroName'},{'id': '148', 'type': 'None', 'children': []},{'id': '149', 'type': 'block', 'children': ['150', '158', '165']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'QtmacsMessage'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'keyseq_copy'},{'id': '157', 'type': 'None', 'children': []},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'setSignalName'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'string', 'children': [], 'value': "'qtesigKeyseqPartial'"},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '174']},{'id': '167', 'type': 'attribute', 'children': ['168', '173']},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'qteMain'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'qtesigKeyseqPartial'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '176', 'type': 'else_clause', 'children': ['177']},{'id': '177', 'type': 'block', 'children': ['178', '194', '204', '211', '222']},{'id': '178', 'type': 'if_statement', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': '_qteFlagRunMacro'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '190']},{'id': '185', 'type': 'attribute', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'qteMain'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'qteRunMacro'},{'id': '190', 'type': 'argument_list', 'children': ['191', '192', '193']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'macroName'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'targetObj'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'keyseq_copy'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'QtmacsMessage'},{'id': '199', 'type': 'argument_list', 'children': ['200', '203']},{'id': '200', 'type': 'tuple', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'macroName'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'keyseq_copy'},{'id': '203', 'type': 'None', 'children': []},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'setSignalName'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'string', 'children': [], 'value': "'qtesigKeyseqComplete'"},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '220']},{'id': '213', 'type': 'attribute', 'children': ['214', '219']},{'id': '214', 'type': 'attribute', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'qteMain'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'qtesigKeyseqComplete'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '229']},{'id': '224', 'type': 'attribute', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '227', 'type': 'identifier', 'children': [], 'value': '_keysequence'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'reset'},{'id': '229', 'type': 'argument_list', 'children': []},{'id': '230', 'type': 'else_clause', 'children': ['231']},{'id': '231', 'type': 'block', 'children': ['232', '329']},{'id': '232', 'type': 'if_statement', 'children': ['233', '234', '309']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'isRegisteredWidget'},{'id': '234', 'type': 'block', 'children': ['235', '243', '253', '263', '272', '283', '291', '298']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'keyseq_copy'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'toString'},{'id': '242', 'type': 'argument_list', 'children': []},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '250', 'type': 'argument_list', 'children': ['251', '252']},{'id': '251', 'type': 'string', 'children': [], 'value': "'<'"},{'id': '252', 'type': 'string', 'children': [], 'value': "'&lt;'"},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '260', 'type': 'argument_list', 'children': ['261', '262']},{'id': '261', 'type': 'string', 'children': [], 'value': "'>'"},{'id': '262', 'type': 'string', 'children': [], 'value': "'&gt;'"},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'string', 'children': [], 'value': "'No macro is bound to <b>{}</b>.'"},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '281']},{'id': '274', 'type': 'attribute', 'children': ['275', '280']},{'id': '275', 'type': 'attribute', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'qteMain'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'qteLogger'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '286', 'type': 'call', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'QtmacsMessage'},{'id': '288', 'type': 'argument_list', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'keyseq_copy'},{'id': '290', 'type': 'None', 'children': []},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'setSignalName'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'string', 'children': [], 'value': "'qtesigKeyseqInvalid'"},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '307']},{'id': '300', 'type': 'attribute', 'children': ['301', '306']},{'id': '301', 'type': 'attribute', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'qteMain'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'qtesigKeyseqInvalid'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '309', 'type': 'else_clause', 'children': ['310']},{'id': '310', 'type': 'block', 'children': ['311']},{'id': '311', 'type': 'if_statement', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '314', 'type': 'identifier', 'children': [], 'value': '_qteFlagRunMacro'},{'id': '315', 'type': 'block', 'children': ['316']},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '323']},{'id': '318', 'type': 'attribute', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'qteMain'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'qteRunMacro'},{'id': '323', 'type': 'argument_list', 'children': ['324', '327', '328']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'QtDelivery'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'targetObj'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'keyseq_copy'},{'id': '329', 'type': 'expression_statement', 'children': ['330']},{'id': '330', 'type': 'call', 'children': ['331', '336']},{'id': '331', 'type': 'attribute', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '334', 'type': 'identifier', 'children': [], 'value': '_keysequence'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'reset'},{'id': '336', 'type': 'argument_list', 'children': []},{'id': '337', 'type': 'expression_statement', 'children': ['338']},{'id': '338', 'type': 'assignment', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '340', 'type': 'call', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'QtmacsMessage'},{'id': '342', 'type': 'argument_list', 'children': ['343', '347']},{'id': '343', 'type': 'tuple', 'children': ['344', '345', '346']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'targetObj'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'keyseq_copy'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'macroName'},{'id': '347', 'type': 'None', 'children': []},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'call', 'children': ['350', '353']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'setSignalName'},{'id': '353', 'type': 'argument_list', 'children': ['354']},{'id': '354', 'type': 'string', 'children': [], 'value': "'qtesigKeyparsed'"},{'id': '355', 'type': 'expression_statement', 'children': ['356']},{'id': '356', 'type': 'call', 'children': ['357', '364']},{'id': '357', 'type': 'attribute', 'children': ['358', '363']},{'id': '358', 'type': 'attribute', 'children': ['359', '362']},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'qteMain'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'qtesigKeyparsed'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'emit'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'msgObj'},{'id': '366', 'type': 'return_statement', 'children': ['367']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'isPartialMatch'}
def qteProcessKey(self, event, targetObj): msgObj = QtmacsMessage((targetObj, event), None) msgObj.setSignalName('qtesigKeypressed') self.qteMain.qtesigKeypressed.emit(msgObj) if event.key() in (QtCore.Qt.Key_Shift, QtCore.Qt.Key_Control, QtCore.Qt.Key_Meta, QtCore.Qt.Key_Alt, QtCore.Qt.Key_AltGr): return False self._keysequence.appendQKeyEvent(event) isRegisteredWidget = hasattr(targetObj, '_qteAdmin') if isRegisteredWidget and hasattr(targetObj._qteAdmin, 'keyMap'): keyMap = targetObj._qteAdmin.keyMap else: keyMap = self.qteMain._qteGlobalKeyMapByReference() (macroName, isPartialMatch) = keyMap.match(self._keysequence) keyseq_copy = QtmacsKeysequence(self._keysequence) if isPartialMatch: if macroName is None: msgObj = QtmacsMessage(keyseq_copy, None) msgObj.setSignalName('qtesigKeyseqPartial') self.qteMain.qtesigKeyseqPartial.emit(msgObj) else: if self._qteFlagRunMacro: self.qteMain.qteRunMacro(macroName, targetObj, keyseq_copy) msgObj = QtmacsMessage((macroName, keyseq_copy), None) msgObj.setSignalName('qtesigKeyseqComplete') self.qteMain.qtesigKeyseqComplete.emit(msgObj) self._keysequence.reset() else: if isRegisteredWidget: tmp = keyseq_copy.toString() tmp = tmp.replace('<', '&lt;') tmp = tmp.replace('>', '&gt;') msg = 'No macro is bound to <b>{}</b>.'.format(tmp) self.qteMain.qteLogger.warning(msg) msgObj = QtmacsMessage(keyseq_copy, None) msgObj.setSignalName('qtesigKeyseqInvalid') self.qteMain.qtesigKeyseqInvalid.emit(msgObj) else: if self._qteFlagRunMacro: self.qteMain.qteRunMacro( self.QtDelivery, targetObj, keyseq_copy) self._keysequence.reset() msgObj = QtmacsMessage((targetObj, keyseq_copy, macroName), None) msgObj.setSignalName('qtesigKeyparsed') self.qteMain.qtesigKeyparsed.emit(msgObj) return isPartialMatch
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'timerEvent'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '6', 'type': 'block', 'children': ['7', '18']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'killTimer'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'timerId'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'if_statement', 'children': ['19', '28', '159', '171']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '25'], 'value': '=='},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'timerId'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_qteTimerRunMacro'},{'id': '28', 'type': 'block', 'children': ['29', '35']},{'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': '_qteTimerRunMacro'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'while_statement', 'children': ['36', '37']},{'id': '36', 'type': 'True', 'children': []},{'id': '37', 'type': 'block', 'children': ['38', '153']},{'id': '38', 'type': 'if_statement', 'children': ['39', '47', '71', '144']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '46'], 'value': '>'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_qteMacroQueue'},{'id': '46', 'type': 'integer', 'children': [], 'value': '0'},{'id': '47', 'type': 'block', 'children': ['48', '62']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '54']},{'id': '50', 'type': 'tuple_pattern', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'macroName'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'qteWidget'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '54', 'type': 'call', 'children': ['55', '60']},{'id': '55', 'type': 'attribute', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_qteMacroQueue'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_qteRunQueuedMacro'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69', '70']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'macroName'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'qteWidget'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '71', 'type': 'elif_clause', 'children': ['72', '80']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '79'], 'value': '>'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_qteKeyEmulationQueue'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'block', 'children': ['81', '123', '134']},{'id': '81', 'type': 'if_statement', 'children': ['82', '87', '96']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '86'], 'value': 'is'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_qteActiveApplet'},{'id': '86', 'type': 'None', 'children': []},{'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': 'receiver'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'qteActiveWindow'},{'id': '95', 'type': 'argument_list', 'children': []},{'id': '96', 'type': 'else_clause', 'children': ['97']},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'if_statement', 'children': ['99', '106', '113']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '105'], 'value': 'is'},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_qteActiveApplet'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_qteActiveWidget'},{'id': '105', 'type': 'None', 'children': []},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'receiver'},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_qteActiveApplet'},{'id': '113', 'type': 'else_clause', 'children': ['114']},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'receiver'},{'id': '118', 'type': 'attribute', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_qteActiveApplet'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_qteActiveWidget'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'keysequence'},{'id': '126', 'type': 'call', 'children': ['127', '132']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': '_qteKeyEmulationQueue'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'integer', 'children': [], 'value': '0'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '141']},{'id': '136', 'type': 'attribute', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': '_qteEventFilter'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'eventFilter'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'receiver'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'keysequence'},{'id': '144', 'type': 'else_clause', 'children': ['145']},{'id': '145', 'type': 'block', 'children': ['146', '152']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': '_qteFocusManager'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'break_statement', 'children': []},{'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': '_qteFocusManager'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'elif_clause', 'children': ['160', '169']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '166'], 'value': '=='},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'timerId'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'debugTimer'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'pass_statement', 'children': []},{'id': '171', 'type': 'else_clause', 'children': ['172']},{'id': '172', 'type': 'block', 'children': ['173', '178']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'string', 'children': [], 'value': "'Unknown timer ID'"},{'id': '178', 'type': 'pass_statement', 'children': []}
def timerEvent(self, event): self.killTimer(event.timerId()) if event.timerId() == self._qteTimerRunMacro: self._qteTimerRunMacro = None while True: if len(self._qteMacroQueue) > 0: (macroName, qteWidget, event) = self._qteMacroQueue.pop(0) self._qteRunQueuedMacro(macroName, qteWidget, event) elif len(self._qteKeyEmulationQueue) > 0: if self._qteActiveApplet is None: receiver = self.qteActiveWindow() else: if self._qteActiveApplet._qteActiveWidget is None: receiver = self._qteActiveApplet else: receiver = self._qteActiveApplet._qteActiveWidget keysequence = self._qteKeyEmulationQueue.pop(0) self._qteEventFilter.eventFilter(receiver, keysequence) else: self._qteFocusManager() break self._qteFocusManager() elif event.timerId() == self.debugTimer: pass else: print('Unknown timer ID') pass
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '37']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteNextApplet'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '17', '22', '27', '32']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_default_parameter', 'children': ['6', '7', '9']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'numSkip'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '9', 'type': 'integer', 'children': [], 'value': '1'},{'id': '10', 'type': 'typed_default_parameter', 'children': ['11', '12', '16']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ofsApp'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'tuple', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'QtmacsApplet'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'typed_default_parameter', 'children': ['18', '19', '21']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'skipInvisible'},{'id': '19', 'type': 'type', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '21', 'type': 'True', 'children': []},{'id': '22', 'type': 'typed_default_parameter', 'children': ['23', '24', '26']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'skipVisible'},{'id': '24', 'type': 'type', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '26', 'type': 'False', 'children': []},{'id': '27', 'type': 'typed_default_parameter', 'children': ['28', '29', '31']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'skipMiniApplet'},{'id': '29', 'type': 'type', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '31', 'type': 'True', 'children': []},{'id': '32', 'type': 'typed_default_parameter', 'children': ['33', '34', '36']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'windowObj'},{'id': '34', 'type': 'type', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'QtmacsWindow'},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'block', 'children': ['38', '54', '66', '73', '82', '120', '138', '157', '167', '178', '292', '304']},{'id': '38', 'type': 'if_statement', 'children': ['39', '44']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ofsApp'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ofsApp'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'qteGetAppletHandle'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ofsApp'},{'id': '54', 'type': 'if_statement', 'children': ['55', '63']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '62'], 'value': '=='},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'None', 'children': []},{'id': '66', 'type': 'if_statement', 'children': ['67', '70']},{'id': '67', 'type': 'boolean_operator', 'children': ['68', '69'], 'value': 'and'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'skipVisible'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'skipInvisible'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'None', 'children': []},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'},{'id': '82', 'type': 'if_statement', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'skipInvisible'},{'id': '84', 'type': 'block', 'children': ['85', '99']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '88', 'type': 'list_comprehension', 'children': ['89', '90', '93']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '93', 'type': 'if_clause', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'qteIsVisible'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'if_statement', 'children': ['100', '103']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'windowObj'},{'id': '102', 'type': 'None', 'children': []},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '107', 'type': 'list_comprehension', 'children': ['108', '109', '112']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '109', 'type': 'for_in_clause', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '112', 'type': 'if_clause', 'children': ['113']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '119'], 'value': '=='},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'qteParentWindow'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'windowObj'},{'id': '120', 'type': 'if_statement', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'skipVisible'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '126', 'type': 'list_comprehension', 'children': ['127', '128', '131']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '131', 'type': 'if_clause', 'children': ['132']},{'id': '132', 'type': 'not_operator', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'qteIsVisible'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'if_statement', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'skipMiniApplet'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'if_statement', 'children': ['142', '147']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '146'], 'value': 'in'},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '147', 'type': 'block', 'children': ['148']},{'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': 'appList'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '157', 'type': 'if_statement', 'children': ['158', '164']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '163'], 'value': '=='},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '163', 'type': 'integer', 'children': [], 'value': '0'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'return_statement', 'children': ['166']},{'id': '166', 'type': 'None', 'children': []},{'id': '167', 'type': 'if_statement', 'children': ['168', '171']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': 'is'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'ofsApp'},{'id': '170', 'type': 'None', 'children': []},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'ofsApp'},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_qteActiveApplet'},{'id': '178', 'type': 'if_statement', 'children': ['179', '184', '286']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'in'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'ofsApp'},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'if_statement', 'children': ['186', '189', '199']},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': 'in'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'ofsApp'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'ofsApp'},{'id': '199', 'type': 'else_clause', 'children': ['200']},{'id': '200', 'type': 'block', 'children': ['201', '212', '222', '232', '249']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'},{'id': '204', 'type': 'call', 'children': ['205', '210']},{'id': '205', 'type': 'attribute', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '208', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'ofsApp'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'glob_list'},{'id': '215', 'type': 'subscript', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '218', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'},{'id': '219', 'type': 'slice', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'},{'id': '221', 'type': 'colon', 'children': []},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'augmented_assignment', 'children': ['224', '225'], 'value': '+='},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'glob_list'},{'id': '225', 'type': 'subscript', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '228', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'},{'id': '229', 'type': 'slice', 'children': ['230', '231']},{'id': '230', 'type': 'colon', 'children': []},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'},{'id': '235', 'type': 'list_comprehension', 'children': ['236', '242', '245']},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '242', 'type': 'for_in_clause', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'glob_list'},{'id': '245', 'type': 'if_clause', 'children': ['246']},{'id': '246', 'type': 'comparison_operator', 'children': ['247', '248'], 'value': 'in'},{'id': '247', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '249', 'type': 'if_statement', 'children': ['250', '256', '278']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '255'], 'value': '=='},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'},{'id': '255', 'type': 'integer', 'children': [], 'value': '0'},{'id': '256', 'type': 'block', 'children': ['257', '264', '276']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '260', 'type': '()', 'children': ['261']},{'id': '261', 'type': 'concatenated_string', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': "'No match between global and local applet list'"},{'id': '263', 'type': 'string', 'children': [], 'value': "' --> Bug.'"},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '271']},{'id': '266', 'type': 'attribute', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'qteLogger'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '271', 'type': 'argument_list', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'stack_info'},{'id': '275', 'type': 'True', 'children': []},{'id': '276', 'type': 'return_statement', 'children': ['277']},{'id': '277', 'type': 'None', 'children': []},{'id': '278', 'type': 'else_clause', 'children': ['279']},{'id': '279', 'type': 'block', 'children': ['280']},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'assignment', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'},{'id': '283', 'type': 'subscript', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'},{'id': '285', 'type': 'integer', 'children': [], 'value': '0'},{'id': '286', 'type': 'else_clause', 'children': ['287']},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'},{'id': '291', 'type': 'integer', 'children': [], 'value': '0'},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'},{'id': '295', 'type': 'binary_operator', 'children': ['296', '300'], 'value': '%'},{'id': '296', 'type': '()', 'children': ['297']},{'id': '297', 'type': 'binary_operator', 'children': ['298', '299'], 'value': '+'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'numSkip'},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '304', 'type': 'return_statement', 'children': ['305']},{'id': '305', 'type': 'subscript', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'appList'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'}
def qteNextApplet(self, numSkip: int=1, ofsApp: (QtmacsApplet, str)=None, skipInvisible: bool=True, skipVisible: bool=False, skipMiniApplet: bool=True, windowObj: QtmacsWindow=None): if isinstance(ofsApp, str): ofsApp = self.qteGetAppletHandle(ofsApp) if len(self._qteAppletList) == 0: return None if skipVisible and skipInvisible: return None appList = list(self._qteAppletList) if skipInvisible: appList = [app for app in appList if app.qteIsVisible()] if windowObj is not None: appList = [app for app in appList if app.qteParentWindow() == windowObj] if skipVisible: appList = [app for app in appList if not app.qteIsVisible()] if skipMiniApplet: if self._qteMiniApplet in appList: appList.remove(self._qteMiniApplet) if len(appList) == 0: return None if ofsApp is None: ofsApp = self._qteActiveApplet if ofsApp in self._qteAppletList: if ofsApp in appList: ofsIdx = appList.index(ofsApp) else: ofsIdx = self._qteAppletList.index(ofsApp) glob_list = self._qteAppletList[ofsIdx:] glob_list += self._qteAppletList[:ofsIdx] ofsIdx = [appList.index(_) for _ in glob_list if _ in appList] if len(ofsIdx) == 0: msg = ('No match between global and local applet list' ' --> Bug.') self.qteLogger.error(msg, stack_info=True) return None else: ofsIdx = ofsIdx[0] else: ofsIdx = 0 ofsIdx = (ofsIdx + numSkip) % len(appList) return appList[ofsIdx]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_qteRunQueuedMacro'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'macroName'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '15']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'widgetObj'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'QtGui'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'QWidget'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'typed_default_parameter', 'children': ['17', '18', '20']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'keysequence'},{'id': '18', 'type': 'type', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'QtmacsKeysequence'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '29', '65', '75', '113', '124', '153']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'qteGetAppletFromWidget'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'widgetObj'},{'id': '29', 'type': 'if_statement', 'children': ['30', '33']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'if_statement', 'children': ['35', '41']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sip'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'isdeleted'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '41', 'type': 'block', 'children': ['42', '46', '55', '64']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '45', 'type': 'string', 'children': [], 'value': "'Ignored macro <b>{}</b> because it targeted a'"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'augmented_assignment', 'children': ['48', '49'], 'value': '+='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': "' nonexistent applet.'"},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'macroName'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'qteLogger'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '64', 'type': 'return_statement', 'children': []},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'macroObj'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'qteGetMacroObject'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'macroName'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'widgetObj'},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'is'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'macroObj'},{'id': '78', 'type': 'None', 'children': []},{'id': '79', 'type': 'block', 'children': ['80', '84', '103', '112']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '83', 'type': 'string', 'children': [], 'value': "'No <b>{}</b>-macro compatible with {}:{}-type applet'"},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93', '98']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'macroName'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'qteAppletSignature'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'widgetObj'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'widgetSignature'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '110']},{'id': '105', 'type': 'attribute', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'qteLogger'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '112', 'type': 'return_statement', 'children': []},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'qteDefVar'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120', '121']},{'id': '119', 'type': 'string', 'children': [], 'value': "'last_key_sequence'"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'keysequence'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '123', 'type': 'string', 'children': [], 'value': '"Last valid key sequence that triggered a macro."'},{'id': '124', 'type': 'if_statement', 'children': ['125', '128', '139']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '127', 'type': 'None', 'children': []},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'macroObj'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'qteApplet'},{'id': '134', 'type': 'assignment', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'macroObj'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'qteWidget'},{'id': '138', 'type': 'None', 'children': []},{'id': '139', 'type': 'else_clause', 'children': ['140']},{'id': '140', 'type': 'block', 'children': ['141', '147']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'macroObj'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'qteApplet'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'macroObj'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'qteWidget'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'widgetObj'},{'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': 'macroObj'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'qtePrepareToRun'},{'id': '158', 'type': 'argument_list', 'children': []}
def _qteRunQueuedMacro(self, macroName: str, widgetObj: QtGui.QWidget=None, keysequence: QtmacsKeysequence=None): app = qteGetAppletFromWidget(widgetObj) if app is not None: if sip.isdeleted(app): msg = 'Ignored macro <b>{}</b> because it targeted a' msg += ' nonexistent applet.'.format(macroName) self.qteLogger.warning(msg) return macroObj = self.qteGetMacroObject(macroName, widgetObj) if macroObj is None: msg = 'No <b>{}</b>-macro compatible with {}:{}-type applet' msg = msg.format(macroName, app.qteAppletSignature(), widgetObj._qteAdmin.widgetSignature) self.qteLogger.warning(msg) return self.qteDefVar('last_key_sequence', keysequence, doc="Last valid key sequence that triggered a macro.") if app is None: macroObj.qteApplet = macroObj.qteWidget = None else: macroObj.qteApplet = app macroObj.qteWidget = widgetObj macroObj.qtePrepareToRun()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteNewApplet'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'appletName'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '13']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'appletID'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'typed_default_parameter', 'children': ['15', '16', '18']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'windowObj'},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'QtmacsWindow'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '55', '95', '128', '168', '206', '254', '264', '303', '310', '322']},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'windowObj'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25', '33']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'windowObj'},{'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': 'qteActiveWindow'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'if_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'windowObj'},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'block', 'children': ['38', '42', '54']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '41', 'type': 'string', 'children': [], 'value': "'Cannot determine the currently active window.'"},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '49']},{'id': '44', 'type': 'attribute', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'qteLogger'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'stack_info'},{'id': '53', 'type': 'True', 'children': []},{'id': '54', 'type': 'return_statement', 'children': []},{'id': '55', 'type': 'if_statement', 'children': ['56', '59']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'appletID'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'block', 'children': ['60', '64']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'while_statement', 'children': ['65', '66']},{'id': '65', 'type': 'True', 'children': []},{'id': '66', 'type': 'block', 'children': ['67', '78']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'appletID'},{'id': '70', 'type': 'binary_operator', 'children': ['71', '74'], 'value': '+'},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'appletName'},{'id': '73', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '78', 'type': 'if_statement', 'children': ['79', '87', '89']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '86'], 'value': 'is'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'qteGetAppletHandle'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'appletID'},{'id': '86', 'type': 'None', 'children': []},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'break_statement', 'children': []},{'id': '89', 'type': 'else_clause', 'children': ['90']},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'augmented_assignment', 'children': ['93', '94'], 'value': '+='},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '94', 'type': 'integer', 'children': [], 'value': '1'},{'id': '95', 'type': 'if_statement', 'children': ['96', '104']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '103'], 'value': 'is'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'qteGetAppletHandle'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'appletID'},{'id': '103', 'type': 'None', 'children': []},{'id': '104', 'type': 'block', 'children': ['105', '114', '126']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': "'Applet with ID <b>{}</b> already exists'"},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'appletID'},{'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': 'qteLogger'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'stack_info'},{'id': '125', 'type': 'True', 'children': []},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'None', 'children': []},{'id': '128', 'type': 'if_statement', 'children': ['129', '134', '158']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'not'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'appletName'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': '_qteRegistryApplets'},{'id': '134', 'type': 'block', 'children': ['135', '144', '156']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': "'Unknown applet <b>{}</b>'"},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'appletName'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '151']},{'id': '146', 'type': 'attribute', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'qteLogger'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'stack_info'},{'id': '155', 'type': 'True', 'children': []},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'None', 'children': []},{'id': '158', 'type': 'else_clause', 'children': ['159']},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '163', 'type': 'subscript', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_qteRegistryApplets'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'appletName'},{'id': '168', 'type': 'try_statement', 'children': ['169', '177']},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'appletID'},{'id': '177', 'type': 'except_clause', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '179', 'type': 'block', 'children': ['180', '189', '204']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'string', 'children': [], 'value': "'Applet <b>{}</b> has a faulty constructor.'"},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'appletID'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '196']},{'id': '191', 'type': 'attribute', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'qteLogger'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198', '201']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '200', 'type': 'True', 'children': []},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'stack_info'},{'id': '203', 'type': 'True', 'children': []},{'id': '204', 'type': 'return_statement', 'children': ['205']},{'id': '205', 'type': 'None', 'children': []},{'id': '206', 'type': 'if_statement', 'children': ['207', '214']},{'id': '207', 'type': 'comparison_operator', 'children': ['208', '213'], 'value': 'is'},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'qteAppletSignature'},{'id': '212', 'type': 'argument_list', 'children': []},{'id': '213', 'type': 'None', 'children': []},{'id': '214', 'type': 'block', 'children': ['215', '228', '232', '236', '240', '252']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': "'Cannot add applet <b>{}</b> '"},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'qteAppletID'},{'id': '227', 'type': 'argument_list', 'children': []},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'augmented_assignment', 'children': ['230', '231'], 'value': '+='},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '231', 'type': 'string', 'children': [], 'value': "'because it has not applet signature.'"},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'augmented_assignment', 'children': ['234', '235'], 'value': '+='},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '235', 'type': 'string', 'children': [], 'value': "' Use self.qteSetAppletSignature in the constructor'"},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'augmented_assignment', 'children': ['238', '239'], 'value': '+='},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '239', 'type': 'string', 'children': [], 'value': "' of the class to fix this.'"},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '247']},{'id': '242', 'type': 'attribute', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'qteLogger'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'stack_info'},{'id': '251', 'type': 'True', 'children': []},{'id': '252', 'type': 'return_statement', 'children': ['253']},{'id': '253', 'type': 'None', 'children': []},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '261']},{'id': '256', 'type': 'attribute', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '259', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263']},{'id': '262', 'type': 'integer', 'children': [], 'value': '0'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '264', 'type': 'if_statement', 'children': ['265', '272']},{'id': '265', 'type': 'comparison_operator', 'children': ['266', '271'], 'value': 'is'},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '270', 'type': 'argument_list', 'children': []},{'id': '271', 'type': 'None', 'children': []},{'id': '272', 'type': 'block', 'children': ['273', '281', '296']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'appLayout'},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'QtGui'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'QHBoxLayout'},{'id': '280', 'type': 'argument_list', 'children': []},{'id': '281', 'type': 'for_statement', 'children': ['282', '283', '288']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '283', 'type': 'attribute', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '286', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'widgetList'},{'id': '288', 'type': 'block', 'children': ['289']},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'appLayout'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'addWidget'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'handle'},{'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': 'app'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'setLayout'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'appLayout'},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'qteReparent'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'None', 'children': []},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'call', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'qteRunHook'},{'id': '315', 'type': 'argument_list', 'children': ['316', '317']},{'id': '316', 'type': 'string', 'children': [], 'value': "'init'"},{'id': '317', 'type': 'call', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'QtmacsMessage'},{'id': '319', 'type': 'argument_list', 'children': ['320', '321']},{'id': '320', 'type': 'None', 'children': []},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '322', 'type': 'return_statement', 'children': ['323']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'app'}
def qteNewApplet(self, appletName: str, appletID: str=None, windowObj: QtmacsWindow=None): if windowObj is None: windowObj = self.qteActiveWindow() if windowObj is None: msg = 'Cannot determine the currently active window.' self.qteLogger.error(msg, stack_info=True) return if appletID is None: cnt = 0 while True: appletID = appletName + '_' + str(cnt) if self.qteGetAppletHandle(appletID) is None: break else: cnt += 1 if self.qteGetAppletHandle(appletID) is not None: msg = 'Applet with ID <b>{}</b> already exists'.format(appletID) self.qteLogger.error(msg, stack_info=True) return None if appletName not in self._qteRegistryApplets: msg = 'Unknown applet <b>{}</b>'.format(appletName) self.qteLogger.error(msg, stack_info=True) return None else: cls = self._qteRegistryApplets[appletName] try: app = cls(appletID) except Exception: msg = 'Applet <b>{}</b> has a faulty constructor.'.format(appletID) self.qteLogger.exception(msg, exc_info=True, stack_info=True) return None if app.qteAppletSignature() is None: msg = 'Cannot add applet <b>{}</b> '.format(app.qteAppletID()) msg += 'because it has not applet signature.' msg += ' Use self.qteSetAppletSignature in the constructor' msg += ' of the class to fix this.' self.qteLogger.error(msg, stack_info=True) return None self._qteAppletList.insert(0, app) if app.layout() is None: appLayout = QtGui.QHBoxLayout() for handle in app._qteAdmin.widgetList: appLayout.addWidget(handle) app.setLayout(appLayout) app.qteReparent(None) self.qteRunHook('init', QtmacsMessage(None, app)) return app
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteAddMiniApplet'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'appletObj'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'QtmacsApplet'},{'id': '9', 'type': 'block', 'children': ['10', '32', '71', '79', '85', '91', '99', '107', '115', '117', '129', '140', '149', '162', '171', '180']},{'id': '10', 'type': 'if_statement', 'children': ['11', '16']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '15'], 'value': 'is'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '21', '30']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '20', 'type': 'string', 'children': [], 'value': "'Cannot replace mini applet more than once.'"},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'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': 'qteLogger'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'if_statement', 'children': ['33', '40']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '39'], 'value': 'is'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'appletObj'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'block', 'children': ['41', '49', '64']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'appLayout'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'QtGui'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'QHBoxLayout'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'for_statement', 'children': ['50', '51', '56']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'appletObj'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'widgetList'},{'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': 'appLayout'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'addWidget'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'appletObj'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'setLayout'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'appLayout'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '78']},{'id': '73', 'type': 'attribute', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'appletObj'},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'isMiniApplet'},{'id': '78', 'type': 'True', 'children': []},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'appletObj'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': '_qteActiveApplet'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'appWin'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'qteActiveWindow'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '106']},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_qteCallingApplet'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '114']},{'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': '_qteMiniApplet'},{'id': '113', 'type': 'identifier', 'children': [], 'value': '_qteCallingWindow'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'appWin'},{'id': '115', 'type': 'delete_statement', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'integer', 'children': [], 'value': '0'},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '136']},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'appWin'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'qteLayoutSplitter'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'addWidget'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '147']},{'id': '142', 'type': 'attribute', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'True', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'wid'},{'id': '152', 'type': 'call', 'children': ['153', '158']},{'id': '153', 'type': 'attribute', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'qteNextWidget'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'numSkip'},{'id': '161', 'type': 'integer', 'children': [], 'value': '0'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '169']},{'id': '164', 'type': 'attribute', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'qteMakeWidgetActive'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'wid'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'qteMakeAppletActive'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'True', 'children': []}
def qteAddMiniApplet(self, appletObj: QtmacsApplet): if self._qteMiniApplet is not None: msg = 'Cannot replace mini applet more than once.' self.qteLogger.warning(msg) return False if appletObj.layout() is None: appLayout = QtGui.QHBoxLayout() for handle in appletObj._qteAdmin.widgetList: appLayout.addWidget(handle) appletObj.setLayout(appLayout) appletObj._qteAdmin.isMiniApplet = True self._qteMiniApplet = appletObj app = self._qteActiveApplet appWin = self.qteActiveWindow() self._qteMiniApplet._qteCallingApplet = app self._qteMiniApplet._qteCallingWindow = appWin del app self._qteAppletList.insert(0, self._qteMiniApplet) appWin.qteLayoutSplitter.addWidget(self._qteMiniApplet) self._qteMiniApplet.show(True) wid = self._qteMiniApplet.qteNextWidget(numSkip=0) self._qteMiniApplet.qteMakeWidgetActive(wid) self.qteMakeAppletActive(self._qteMiniApplet) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteKillMiniApplet'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '41', '175', '183', '191']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'is'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': []},{'id': '14', 'type': 'if_statement', 'children': ['15', '24']},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'qteIsMiniApplet'},{'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': '_qteMiniApplet'},{'id': '24', 'type': 'block', 'children': ['25', '32']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '28', 'type': '()', 'children': ['29']},{'id': '29', 'type': 'concatenated_string', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'Mini applet does not have its mini applet flag set.'"},{'id': '31', 'type': 'string', 'children': [], 'value': "' Ignored.'"},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'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': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'qteLogger'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '41', 'type': 'if_statement', 'children': ['42', '49', '63']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': 'not'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'},{'id': '49', 'type': 'block', 'children': ['50', '54']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '53', 'type': 'string', 'children': [], 'value': "'Custom mini applet not in applet list --> Bug.'"},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '61']},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'qteLogger'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '63', 'type': 'else_clause', 'children': ['64']},{'id': '64', 'type': 'block', 'children': ['65', '97', '105', '116', '164']},{'id': '65', 'type': 'try_statement', 'children': ['66', '75']},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'qteToBeKilled'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'except_clause', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '77', 'type': 'block', 'children': ['78', '82']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '81', 'type': 'string', 'children': [], 'value': "'qteToBeKilledRoutine is faulty'"},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '89']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'qteLogger'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91', '94']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '93', 'type': 'True', 'children': []},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'stack_info'},{'id': '96', 'type': 'True', 'children': []},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'win'},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_qteCallingWindow'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'qteNextApplet'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'windowObj'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'win'},{'id': '116', 'type': 'if_statement', 'children': ['117', '120', '128']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'is'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '119', 'type': 'None', 'children': []},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'qteMakeAppletActive'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '128', 'type': 'else_clause', 'children': ['129']},{'id': '129', 'type': 'block', 'children': ['130', '144']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'app'},{'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': 'qteNextApplet'},{'id': '137', 'type': 'argument_list', 'children': ['138', '141']},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'skipInvisible'},{'id': '140', 'type': 'False', 'children': []},{'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'skipVisible'},{'id': '143', 'type': 'True', 'children': []},{'id': '144', 'type': 'if_statement', 'children': ['145', '148', '156']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'is'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '147', 'type': 'None', 'children': []},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'qteMakeAppletActive'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '156', 'type': 'else_clause', 'children': ['157']},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': '_qteActiveApplet'},{'id': '163', 'type': 'None', 'children': []},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '171']},{'id': '166', 'type': 'attribute', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '182']},{'id': '177', 'type': 'attribute', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '182', 'type': 'argument_list', 'children': []},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '190']},{'id': '185', 'type': 'attribute', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '188', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'deleteLater'},{'id': '190', 'type': 'argument_list', 'children': []},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '195', 'type': 'identifier', 'children': [], 'value': '_qteMiniApplet'},{'id': '196', 'type': 'None', 'children': []}
def qteKillMiniApplet(self): if self._qteMiniApplet is None: return if not self.qteIsMiniApplet(self._qteMiniApplet): msg = ('Mini applet does not have its mini applet flag set.' ' Ignored.') self.qteLogger.warning(msg) if self._qteMiniApplet not in self._qteAppletList: msg = 'Custom mini applet not in applet list --> Bug.' self.qteLogger.warning(msg) else: try: self._qteMiniApplet.qteToBeKilled() except Exception: msg = 'qteToBeKilledRoutine is faulty' self.qteLogger.exception(msg, exc_info=True, stack_info=True) win = self._qteMiniApplet._qteCallingWindow app = self.qteNextApplet(windowObj=win) if app is not None: self.qteMakeAppletActive(app) else: app = self.qteNextApplet(skipInvisible=False, skipVisible=True) if app is not None: self.qteMakeAppletActive(app) else: self._qteActiveApplet = None self._qteAppletList.remove(self._qteMiniApplet) self._qteMiniApplet.close() self._qteMiniApplet.deleteLater() self._qteMiniApplet = None