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', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '24', '34', '38', '133', '137', '141', '198', '263']},{'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': 'quiet'},{'id': '11', 'type': 'block', 'children': ['12', '14', '16', '18']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '14', 'type': 'print_statement', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': '"Preprocessing input..."'},{'id': '16', 'type': 'print_statement', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': '"Raw response:"'},{'id': '18', 'type': 'print_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': 'display'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'if_statement', 'children': ['25', '29']},{'id': '25', 'type': 'not_operator', 'children': ['26']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '29', 'type': 'block', 'children': ['30', '32']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '32', 'type': 'print_statement', 'children': ['33']},{'id': '33', 'type': 'string', 'children': [], 'value': '"Cleaning words..."'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'while_statement', 'children': ['39', '47']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '<'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'unit_list'},{'id': '47', 'type': 'block', 'children': ['48', '58', '114']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '51', 'type': 'attribute', 'children': ['52', '57']},{'id': '52', 'type': 'subscript', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'unit_list'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '58', 'type': 'if_statement', 'children': ['59', '64', '99']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '63'], 'value': '=='},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '63', 'type': 'string', 'children': [], 'value': '"PHONETIC"'},{'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': 'test'},{'id': '68', 'type': '()', 'children': ['69']},{'id': '69', 'type': 'boolean_operator', 'children': ['70', '90'], 'value': 'and'},{'id': '70', 'type': 'boolean_operator', 'children': ['71', '87'], 'value': 'and'},{'id': '71', 'type': 'boolean_operator', 'children': ['72', '80'], 'value': 'and'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'letter_or_category'},{'id': '80', 'type': 'not_operator', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'not'},{'id': '88', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '96'], 'value': 'in'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '95', 'type': 'argument_list', 'children': []},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'english_words'},{'id': '99', 'type': 'elif_clause', 'children': ['100', '105']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': '=='},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '104', 'type': 'string', 'children': [], 'value': '"SEMANTIC"'},{'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': 'test'},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'in'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'permissible_words'},{'id': '114', 'type': 'if_statement', 'children': ['115', '117', '127']},{'id': '115', 'type': 'not_operator', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'remove_unit'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '127', 'type': 'else_clause', 'children': ['128']},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'augmented_assignment', 'children': ['131', '132'], 'value': '+='},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '136', 'type': 'integer', 'children': [], 'value': '0'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'finished'},{'id': '140', 'type': 'False', 'children': []},{'id': '141', 'type': 'while_statement', 'children': ['142', '152']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '<'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '144', 'type': 'binary_operator', 'children': ['145', '151'], 'value': '-'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'unit_list'},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'if_statement', 'children': ['154', '182', '192']},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '167', '168'], 'value': '=='},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'stemmer'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'stem'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'attribute', 'children': ['161', '166']},{'id': '161', 'type': 'subscript', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'unit_list'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '167', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'stemmer'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'stem'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'attribute', 'children': ['174', '181']},{'id': '174', 'type': 'subscript', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'unit_list'},{'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '+'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '180', 'type': 'integer', 'children': [], 'value': '1'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'text'},{'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': 'self'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'combine_same_stem_units'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '192', 'type': 'else_clause', 'children': ['193']},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'augmented_assignment', 'children': ['196', '197'], 'value': '+='},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'current_index'},{'id': '197', 'type': 'integer', 'children': [], 'value': '1'},{'id': '198', 'type': 'if_statement', 'children': ['199', '204']},{'id': '199', 'type': 'comparison_operator', 'children': ['200', '203'], 'value': '=='},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '203', 'type': 'string', 'children': [], 'value': '"PHONETIC"'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'for_statement', 'children': ['206', '207', '210']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'unit_list'},{'id': '210', 'type': 'block', 'children': ['211', '217', '232', '257']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '217', 'type': 'if_statement', 'children': ['218', '223']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'in'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'cmudict'},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'phonetic_representation'},{'id': '227', 'type': 'subscript', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'cmudict'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '232', 'type': 'if_statement', 'children': ['233', '238']},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': 'not'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'cmudict'},{'id': '238', 'type': 'block', 'children': ['239', '248']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'phonetic_representation'},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'generate_phonetic_representation'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'phonetic_representation'},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'modify_phonetic_representation'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'phonetic_representation'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'phonetic_representation'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'phonetic_representation'},{'id': '263', 'type': 'if_statement', 'children': ['264', '268']},{'id': '264', 'type': 'not_operator', 'children': ['265']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '268', 'type': 'block', 'children': ['269', '271', '273']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '271', 'type': 'print_statement', 'children': ['272']},{'id': '272', 'type': 'string', 'children': [], 'value': '"Cleaned response:"'},{'id': '273', 'type': 'print_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'display'},{'id': '278', 'type': 'argument_list', 'children': []}
def clean(self): if not self.quiet: print print "Preprocessing input..." print "Raw response:" print self.display() if not self.quiet: print print "Cleaning words..." current_index = 0 while current_index < len(self.unit_list): word = self.unit_list[current_index].text if self.type == "PHONETIC": test = (word.startswith(self.letter_or_category) and not word.endswith('-') and '_' not in word and word.lower() in self.english_words) elif self.type == "SEMANTIC": test = word in self.permissible_words if not test: self.remove_unit(index = current_index) else: current_index += 1 current_index = 0 finished = False while current_index < len(self.unit_list) - 1: if stemmer.stem(self.unit_list[current_index].text) == \ stemmer.stem(self.unit_list[current_index + 1].text): self.combine_same_stem_units(index = current_index) else: current_index += 1 if self.type == "PHONETIC": for unit in self.unit_list: word = unit.text if word in self.cmudict: phonetic_representation = self.cmudict[word] if word not in self.cmudict: phonetic_representation = self.generate_phonetic_representation(word) phonetic_representation = self.modify_phonetic_representation(phonetic_representation) unit.phonetic_representation = phonetic_representation if not self.quiet: print print "Cleaned response:" print self.display()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_raw_counts'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '20', '351', '378', '405']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'words_said'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '25']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'parsed_response'},{'id': '25', 'type': 'block', 'children': ['26', '32', '36', '105']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '35', 'type': 'False', 'children': []},{'id': '36', 'type': 'if_statement', 'children': ['37', '42', '89']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': '=='},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '41', 'type': 'string', 'children': [], 'value': '"PHONETIC"'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '46', 'type': '()', 'children': ['47']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '80'], 'value': 'and'},{'id': '48', 'type': 'boolean_operator', 'children': ['49', '73'], 'value': 'and'},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '70'], 'value': 'and'},{'id': '50', 'type': 'boolean_operator', 'children': ['51', '67'], 'value': 'and'},{'id': '51', 'type': 'boolean_operator', 'children': ['52', '64'], 'value': 'and'},{'id': '52', 'type': 'boolean_operator', 'children': ['53', '61'], 'value': 'and'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'letter'},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'not'},{'id': '62', 'type': 'string', 'children': [], 'value': '"T_"'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'not'},{'id': '65', 'type': 'string', 'children': [], 'value': '"E_"'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'not'},{'id': '68', 'type': 'string', 'children': [], 'value': '"!"'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'not'},{'id': '71', 'type': 'string', 'children': [], 'value': '"FILLEDPAUSE_"'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '73', 'type': 'not_operator', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '86'], 'value': 'in'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'english_words'},{'id': '89', 'type': 'elif_clause', 'children': ['90', '95']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': '=='},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '94', 'type': 'string', 'children': [], 'value': '"SEMANTIC"'},{'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': 'test'},{'id': '99', 'type': '()', 'children': ['100']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'in'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'permissible_words'},{'id': '105', 'type': 'if_statement', 'children': ['106', '107', '209', '243', '273', '307']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '107', 'type': 'block', 'children': ['108', '116', '124', '195', '202']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'augmented_assignment', 'children': ['110', '115'], 'value': '+='},{'id': '110', 'type': 'subscript', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '114', 'type': 'string', 'children': [], 'value': "'COUNT_total_words'"},{'id': '115', 'type': 'integer', 'children': [], 'value': '1'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'augmented_assignment', 'children': ['118', '123'], 'value': '+='},{'id': '118', 'type': 'subscript', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '122', 'type': 'string', 'children': [], 'value': "'COUNT_permissible_words'"},{'id': '123', 'type': 'integer', 'children': [], 'value': '1'},{'id': '124', 'type': 'if_statement', 'children': ['125', '134', '150', '186']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '127', 'type': 'generator_expression', 'children': ['128', '131']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '=='},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '131', 'type': 'for_in_clause', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'words_said'},{'id': '134', 'type': 'block', 'children': ['135', '143']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'augmented_assignment', 'children': ['137', '142'], 'value': '+='},{'id': '137', 'type': 'subscript', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '141', 'type': 'string', 'children': [], 'value': "'COUNT_exact_repetitions'"},{'id': '142', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'labels'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'string', 'children': [], 'value': "'EXACT REPETITION'"},{'id': '150', 'type': 'elif_clause', 'children': ['151', '170']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '153', 'type': 'generator_expression', 'children': ['154', '167']},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '161'], 'value': '=='},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'stemmer'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'stem'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'stemmer'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'stem'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '167', 'type': 'for_in_clause', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'words_said'},{'id': '170', 'type': 'block', 'children': ['171', '179']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'augmented_assignment', 'children': ['173', '178'], 'value': '+='},{'id': '173', 'type': 'subscript', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '177', 'type': 'string', 'children': [], 'value': "'COUNT_stem_repetitions'"},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'labels'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'string', 'children': [], 'value': "'STEM REPETITION'"},{'id': '186', 'type': 'else_clause', 'children': ['187']},{'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': 'labels'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'string', 'children': [], 'value': "'PERMISSIBLE WORD'"},{'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': 'words_said'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'word'},{'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': 'words'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '209', 'type': 'elif_clause', 'children': ['210', '220']},{'id': '210', 'type': 'call', 'children': ['211', '218']},{'id': '211', 'type': 'attribute', 'children': ['212', '217']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '216', 'type': 'argument_list', 'children': []},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'string', 'children': [], 'value': "'e_'"},{'id': '220', 'type': 'block', 'children': ['221', '229', '236']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'augmented_assignment', 'children': ['223', '228'], 'value': '+='},{'id': '223', 'type': 'subscript', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '227', 'type': 'string', 'children': [], 'value': "'COUNT_examiner_words'"},{'id': '228', 'type': 'integer', 'children': [], 'value': '1'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'string', 'children': [], 'value': "'EXAMINER WORD'"},{'id': '243', 'type': 'elif_clause', 'children': ['244', '250']},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '250', 'type': 'block', 'children': ['251', '259', '266']},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'augmented_assignment', 'children': ['253', '258'], 'value': '+='},{'id': '253', 'type': 'subscript', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '257', 'type': 'string', 'children': [], 'value': "'COUNT_word_fragments'"},{'id': '258', 'type': 'integer', 'children': [], 'value': '1'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'string', 'children': [], 'value': "'WORD FRAGMENT'"},{'id': '273', 'type': 'elif_clause', 'children': ['274', '284']},{'id': '274', 'type': 'call', 'children': ['275', '282']},{'id': '275', 'type': 'attribute', 'children': ['276', '281']},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '280', 'type': 'argument_list', 'children': []},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'string', 'children': [], 'value': "'filledpause'"},{'id': '284', 'type': 'block', 'children': ['285', '293', '300']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'augmented_assignment', 'children': ['287', '292'], 'value': '+='},{'id': '287', 'type': 'subscript', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '291', 'type': 'string', 'children': [], 'value': "'COUNT_filled_pauses'"},{'id': '292', 'type': 'integer', 'children': [], 'value': '1'},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'string', 'children': [], 'value': "'FILLED PAUSE'"},{'id': '307', 'type': 'elif_clause', 'children': ['308', '320']},{'id': '308', 'type': 'comparison_operator', 'children': ['309', '314'], 'value': 'not'},{'id': '309', 'type': 'call', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '313', 'type': 'argument_list', 'children': []},{'id': '314', 'type': 'list', 'children': ['315', '316', '317', '318', '319'], 'value': "['!sil', 't_noise', 't_cough', 't_lipsmack', 't_breath']"},{'id': '315', 'type': 'string', 'children': [], 'value': "'!sil'"},{'id': '316', 'type': 'string', 'children': [], 'value': "'t_noise'"},{'id': '317', 'type': 'string', 'children': [], 'value': "'t_cough'"},{'id': '318', 'type': 'string', 'children': [], 'value': "'t_lipsmack'"},{'id': '319', 'type': 'string', 'children': [], 'value': "'t_breath'"},{'id': '320', 'type': 'block', 'children': ['321', '329', '337', '344']},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'augmented_assignment', 'children': ['323', '328'], 'value': '+='},{'id': '323', 'type': 'subscript', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '327', 'type': 'string', 'children': [], 'value': "'COUNT_total_words'"},{'id': '328', 'type': 'integer', 'children': [], 'value': '1'},{'id': '329', 'type': 'expression_statement', 'children': ['330']},{'id': '330', 'type': 'augmented_assignment', 'children': ['331', '336'], 'value': '+='},{'id': '331', 'type': 'subscript', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '335', 'type': 'string', 'children': [], 'value': "'COUNT_asides'"},{'id': '336', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'words'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '342', 'type': 'argument_list', 'children': ['343']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'string', 'children': [], 'value': "'ASIDE'"},{'id': '351', 'type': 'if_statement', 'children': ['352', '356']},{'id': '352', 'type': 'not_operator', 'children': ['353']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '356', 'type': 'block', 'children': ['357', '359', '361']},{'id': '357', 'type': 'expression_statement', 'children': ['358']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '359', 'type': 'print_statement', 'children': ['360']},{'id': '360', 'type': 'string', 'children': [], 'value': '"Labels:"'},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'call', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'print_table'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'list_comprehension', 'children': ['366', '369']},{'id': '366', 'type': 'tuple', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '369', 'type': 'for_in_clause', 'children': ['370', '373']},{'id': '370', 'type': 'pattern_list', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '373', 'type': 'call', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '375', 'type': 'argument_list', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '378', 'type': 'expression_statement', 'children': ['379']},{'id': '379', 'type': 'assignment', 'children': ['380', '385', '386']},{'id': '380', 'type': 'subscript', 'children': ['381', '384']},{'id': '381', 'type': 'attribute', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '384', 'type': 'string', 'children': [], 'value': "'COUNT_unique_permissible_words'"},{'id': '385', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '386', 'type': 'binary_operator', 'children': ['387', '399', '400'], 'value': '-'},{'id': '387', 'type': 'binary_operator', 'children': ['388', '393', '394'], 'value': '-'},{'id': '388', 'type': 'subscript', 'children': ['389', '392']},{'id': '389', 'type': 'attribute', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '392', 'type': 'string', 'children': [], 'value': "'COUNT_permissible_words'"},{'id': '393', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '394', 'type': 'subscript', 'children': ['395', '398']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '398', 'type': 'string', 'children': [], 'value': "'COUNT_exact_repetitions'"},{'id': '399', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '400', 'type': 'subscript', 'children': ['401', '404']},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '404', 'type': 'string', 'children': [], 'value': "'COUNT_stem_repetitions'"},{'id': '405', 'type': 'if_statement', 'children': ['406', '410']},{'id': '406', 'type': 'not_operator', 'children': ['407']},{'id': '407', 'type': 'attribute', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '410', 'type': 'block', 'children': ['411', '413', '415', '432', '438']},{'id': '411', 'type': 'expression_statement', 'children': ['412']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '413', 'type': 'print_statement', 'children': ['414']},{'id': '414', 'type': 'string', 'children': [], 'value': '"Counts:"'},{'id': '415', 'type': 'expression_statement', 'children': ['416']},{'id': '416', 'type': 'assignment', 'children': ['417', '418']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'collection_measures'},{'id': '418', 'type': 'list_comprehension', 'children': ['419', '420', '425']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '420', 'type': 'for_in_clause', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '422', 'type': 'attribute', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '425', 'type': 'if_clause', 'children': ['426']},{'id': '426', 'type': 'call', 'children': ['427', '430']},{'id': '427', 'type': 'attribute', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '430', 'type': 'argument_list', 'children': ['431']},{'id': '431', 'type': 'string', 'children': [], 'value': '"COUNT_"'},{'id': '432', 'type': 'expression_statement', 'children': ['433']},{'id': '433', 'type': 'call', 'children': ['434', '437']},{'id': '434', 'type': 'attribute', 'children': ['435', '436']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'collection_measures'},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '437', 'type': 'argument_list', 'children': []},{'id': '438', 'type': 'if_statement', 'children': ['439', '443']},{'id': '439', 'type': 'not_operator', 'children': ['440']},{'id': '440', 'type': 'attribute', 'children': ['441', '442']},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '443', 'type': 'block', 'children': ['444']},{'id': '444', 'type': 'expression_statement', 'children': ['445']},{'id': '445', 'type': 'call', 'children': ['446', '447']},{'id': '446', 'type': 'identifier', 'children': [], 'value': 'print_table'},{'id': '447', 'type': 'argument_list', 'children': ['448']},{'id': '448', 'type': 'list_comprehension', 'children': ['449', '459']},{'id': '449', 'type': 'tuple', 'children': ['450', '451']},{'id': '450', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '451', 'type': 'call', 'children': ['452', '453']},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '453', 'type': 'argument_list', 'children': ['454']},{'id': '454', 'type': 'subscript', 'children': ['455', '458']},{'id': '455', 'type': 'attribute', 'children': ['456', '457']},{'id': '456', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '457', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '458', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '459', 'type': 'for_in_clause', 'children': ['460', '461']},{'id': '460', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '461', 'type': 'identifier', 'children': [], 'value': 'collection_measures'}
def get_raw_counts(self): words = [] labels = [] words_said = set() for unit in self.parsed_response: word = unit.text test = False if self.type == "PHONETIC": test = (word.startswith(self.letter) and "T_" not in word and "E_" not in word and "!" not in word and "FILLEDPAUSE_" not in word and not word.endswith('-') and word.lower() in self.english_words) elif self.type == "SEMANTIC": test = (word in self.permissible_words) if test: self.measures['COUNT_total_words'] += 1 self.measures['COUNT_permissible_words'] += 1 if any(word == w for w in words_said): self.measures['COUNT_exact_repetitions'] += 1 labels.append('EXACT REPETITION') elif any(stemmer.stem(word) == stemmer.stem(w) for w in words_said): self.measures['COUNT_stem_repetitions'] += 1 labels.append('STEM REPETITION') else: labels.append('PERMISSIBLE WORD') words_said.add(word) words.append(word) elif word.lower().startswith('e_'): self.measures['COUNT_examiner_words'] += 1 words.append(word) labels.append('EXAMINER WORD') elif word.endswith('-'): self.measures['COUNT_word_fragments'] += 1 words.append(word) labels.append('WORD FRAGMENT') elif word.lower().startswith('filledpause'): self.measures['COUNT_filled_pauses'] += 1 words.append(word) labels.append('FILLED PAUSE') elif word.lower() not in ['!sil', 't_noise', 't_cough', 't_lipsmack', 't_breath']: self.measures['COUNT_total_words'] += 1 self.measures['COUNT_asides'] += 1 words.append(word) labels.append('ASIDE') if not self.quiet: print print "Labels:" print_table([(word,label) for word,label in zip(words,labels)]) self.measures['COUNT_unique_permissible_words'] = \ self.measures['COUNT_permissible_words'] - \ self.measures['COUNT_exact_repetitions'] - \ self.measures['COUNT_stem_repetitions'] if not self.quiet: print print "Counts:" collection_measures = [x for x in self.measures if x.startswith("COUNT_")] collection_measures.sort() if not self.quiet: print_table([(k, str(self.measures[k])) for k in collection_measures])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute_similarity_score'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'unit1'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'unit2'},{'id': '7', 'type': 'block', 'children': ['8', '380']},{'id': '8', 'type': 'if_statement', 'children': ['9', '14', '224']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': '=='},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '13', 'type': 'string', 'children': [], 'value': '"PHONETIC"'},{'id': '14', 'type': 'block', 'children': ['15', '21', '27']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'unit1'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'phonetic_representation'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'unit2'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'phonetic_representation'},{'id': '27', 'type': 'if_statement', 'children': ['28', '33', '178']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': '=='},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'current_similarity_measure'},{'id': '32', 'type': 'string', 'children': [], 'value': '"phone"'},{'id': '33', 'type': 'block', 'children': ['34', '48', '69', '78', '166', '176']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '39']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'word1_length'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'word2_length'},{'id': '39', 'type': 'expression_list', 'children': ['40', '44']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '48', 'type': 'if_statement', 'children': ['49', '52']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '>'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'word1_length'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'word2_length'},{'id': '52', 'type': 'block', 'children': ['53', '61']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '58', 'type': 'expression_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '66']},{'id': '63', 'type': 'pattern_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'word1_length'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'word2_length'},{'id': '66', 'type': 'expression_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'word2_length'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'word1_length'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '+'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'word1_length'},{'id': '77', 'type': 'integer', 'children': [], 'value': '1'},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '87']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '+'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'word2_length'},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'block', 'children': ['88', '102']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '93']},{'id': '90', 'type': 'pattern_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '93', 'type': 'expression_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '98'], 'value': '+'},{'id': '96', 'type': 'list', 'children': ['97'], 'value': '[i]'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '98', 'type': 'binary_operator', 'children': ['99', '101'], 'value': '*'},{'id': '99', 'type': 'list', 'children': ['100'], 'value': '[0]'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'word1_length'},{'id': '102', 'type': 'for_statement', 'children': ['103', '104', '111']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '+'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'word1_length'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'block', 'children': ['112', '130', '138', '155']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '117']},{'id': '114', 'type': 'pattern_list', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '117', 'type': 'expression_list', 'children': ['118', '123']},{'id': '118', 'type': 'binary_operator', 'children': ['119', '122'], 'value': '+'},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '129'], 'value': '+'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '-'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'change'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '-'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'if_statement', 'children': ['139', '150']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '145'], 'value': '!='},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '142', 'type': 'binary_operator', 'children': ['143', '144'], 'value': '-'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '144', 'type': 'integer', 'children': [], 'value': '1'},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '-'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'augmented_assignment', 'children': ['153', '154'], 'value': '+='},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '154', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'current'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164', '165']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'phonetic_similarity_score'},{'id': '169', 'type': 'binary_operator', 'children': ['170', '171'], 'value': '-'},{'id': '170', 'type': 'integer', 'children': [], 'value': '1'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '175'], 'value': '/'},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'word1_length'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'word2_length'},{'id': '176', 'type': 'return_statement', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'phonetic_similarity_score'},{'id': '178', 'type': 'elif_clause', 'children': ['179', '184']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '183'], 'value': '=='},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'current_similarity_measure'},{'id': '183', 'type': 'string', 'children': [], 'value': '"biphone"'},{'id': '184', 'type': 'block', 'children': ['185', '222']},{'id': '185', 'type': 'if_statement', 'children': ['186', '211', '216']},{'id': '186', 'type': 'boolean_operator', 'children': ['187', '198'], 'value': 'or'},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '193'], 'value': '=='},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '190', 'type': 'slice', 'children': ['191', '192']},{'id': '191', 'type': 'colon', 'children': []},{'id': '192', 'type': 'integer', 'children': [], 'value': '2'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '195', 'type': 'slice', 'children': ['196', '197']},{'id': '196', 'type': 'colon', 'children': []},{'id': '197', 'type': 'integer', 'children': [], 'value': '2'},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '205'], 'value': '=='},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '201', 'type': 'slice', 'children': ['202', '204']},{'id': '202', 'type': 'unary_operator', 'children': ['203'], 'value': '-'},{'id': '203', 'type': 'integer', 'children': [], 'value': '2'},{'id': '204', 'type': 'colon', 'children': []},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '207', 'type': 'slice', 'children': ['208', '210']},{'id': '208', 'type': 'unary_operator', 'children': ['209'], 'value': '-'},{'id': '209', 'type': 'integer', 'children': [], 'value': '2'},{'id': '210', 'type': 'colon', 'children': []},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'common_biphone_score'},{'id': '215', 'type': 'integer', 'children': [], 'value': '1'},{'id': '216', 'type': 'else_clause', 'children': ['217']},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'common_biphone_score'},{'id': '221', 'type': 'integer', 'children': [], 'value': '0'},{'id': '222', 'type': 'return_statement', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'common_biphone_score'},{'id': '224', 'type': 'elif_clause', 'children': ['225', '230']},{'id': '225', 'type': 'comparison_operator', 'children': ['226', '229'], 'value': '=='},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '229', 'type': 'string', 'children': [], 'value': '"SEMANTIC"'},{'id': '230', 'type': 'block', 'children': ['231', '237', '243']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'unit1'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'unit2'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '243', 'type': 'if_statement', 'children': ['244', '249', '328']},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '248'], 'value': '=='},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'current_similarity_measure'},{'id': '248', 'type': 'string', 'children': [], 'value': '"lsa"'},{'id': '249', 'type': 'block', 'children': ['250', '258', '266', '285', '301', '317', '326']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'w1_vec'},{'id': '253', 'type': 'subscript', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'term_vectors'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'w2_vec'},{'id': '261', 'type': 'subscript', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'term_vectors'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'list_comprehension', 'children': ['273', '276']},{'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '*'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'w1'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'w2'},{'id': '276', 'type': 'for_in_clause', 'children': ['277', '280']},{'id': '277', 'type': 'pattern_list', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'w1'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'w2'},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '282', 'type': 'argument_list', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'w1_vec'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'w2_vec'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'norm1'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'call', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'list_comprehension', 'children': ['295', '298']},{'id': '295', 'type': 'binary_operator', 'children': ['296', '297'], 'value': '*'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '298', 'type': 'for_in_clause', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'w1_vec'},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'assignment', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'norm2'},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'list_comprehension', 'children': ['311', '314']},{'id': '311', 'type': 'binary_operator', 'children': ['312', '313'], 'value': '*'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '314', 'type': 'for_in_clause', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'w2_vec'},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'assignment', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'semantic_relatedness_score'},{'id': '320', 'type': 'binary_operator', 'children': ['321', '322'], 'value': '/'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '322', 'type': '()', 'children': ['323']},{'id': '323', 'type': 'binary_operator', 'children': ['324', '325'], 'value': '*'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'norm1'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'norm2'},{'id': '326', 'type': 'return_statement', 'children': ['327']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'semantic_relatedness_score'},{'id': '328', 'type': 'elif_clause', 'children': ['329', '334']},{'id': '329', 'type': 'comparison_operator', 'children': ['330', '333'], 'value': '=='},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'current_similarity_measure'},{'id': '333', 'type': 'string', 'children': [], 'value': '"custom"'},{'id': '334', 'type': 'block', 'children': ['335', '378']},{'id': '335', 'type': 'try_statement', 'children': ['336', '347']},{'id': '336', 'type': 'block', 'children': ['337']},{'id': '337', 'type': 'expression_statement', 'children': ['338']},{'id': '338', 'type': 'assignment', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'similarity'},{'id': '340', 'type': 'subscript', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'custom_similarity_scores'},{'id': '344', 'type': 'tuple', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '347', 'type': 'except_clause', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '349', 'type': 'block', 'children': ['350']},{'id': '350', 'type': 'try_statement', 'children': ['351', '362']},{'id': '351', 'type': 'block', 'children': ['352']},{'id': '352', 'type': 'expression_statement', 'children': ['353']},{'id': '353', 'type': 'assignment', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'similarity'},{'id': '355', 'type': 'subscript', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'custom_similarity_scores'},{'id': '359', 'type': 'tuple', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '362', 'type': 'except_clause', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '364', 'type': 'block', 'children': ['365']},{'id': '365', 'type': 'if_statement', 'children': ['366', '369', '374']},{'id': '366', 'type': 'comparison_operator', 'children': ['367', '368'], 'value': '=='},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '369', 'type': 'block', 'children': ['370']},{'id': '370', 'type': 'return_statement', 'children': ['371']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'same_word_similarity'},{'id': '374', 'type': 'else_clause', 'children': ['375']},{'id': '375', 'type': 'block', 'children': ['376']},{'id': '376', 'type': 'return_statement', 'children': ['377']},{'id': '377', 'type': 'integer', 'children': [], 'value': '0'},{'id': '378', 'type': 'return_statement', 'children': ['379']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'similarity'},{'id': '380', 'type': 'return_statement', 'children': ['381']},{'id': '381', 'type': 'None', 'children': []}
def compute_similarity_score(self, unit1, unit2): if self.type == "PHONETIC": word1 = unit1.phonetic_representation word2 = unit2.phonetic_representation if self.current_similarity_measure == "phone": word1_length, word2_length = len(word1), len(word2) if word1_length > word2_length: word1, word2 = word2, word1 word1_length, word2_length = word2_length, word1_length current = range(word1_length + 1) for i in range(1, word2_length + 1): previous, current = current, [i] + [0] * word1_length for j in range(1, word1_length + 1): add, delete = previous[j] + 1, current[j - 1] + 1 change = previous[j - 1] if word1[j - 1] != word2[i - 1]: change += 1 current[j] = min(add, delete, change) phonetic_similarity_score = 1 - current[word1_length] / word2_length return phonetic_similarity_score elif self.current_similarity_measure == "biphone": if word1[:2] == word2[:2] or word1[-2:] == word2[-2:]: common_biphone_score = 1 else: common_biphone_score = 0 return common_biphone_score elif self.type == "SEMANTIC": word1 = unit1.text word2 = unit2.text if self.current_similarity_measure == "lsa": w1_vec = self.term_vectors[word1] w2_vec = self.term_vectors[word2] dot = sum([w1*w2 for w1,w2 in zip(w1_vec, w2_vec)]) norm1 = sqrt(sum([w*w for w in w1_vec])) norm2 = sqrt(sum([w*w for w in w2_vec])) semantic_relatedness_score = dot/(norm1 * norm2) return semantic_relatedness_score elif self.current_similarity_measure == "custom": try: similarity = self.custom_similarity_scores[(word1,word2)] except KeyError: try: similarity = self.custom_similarity_scores[(word2,word1)] except KeyError: if word1 == word2: return self.same_word_similarity else: return 0 return similarity return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute_pairwise_similarity_score'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '93', '107']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'all_scores'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'for_statement', 'children': ['15', '18', '24']},{'id': '15', 'type': 'pattern_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'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': 'parsed_response'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'for_statement', 'children': ['26', '29', '35']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'other_unit'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'parsed_response'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '!='},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '40', 'type': 'block', 'children': ['41', '47', '53']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '44', 'type': 'tuple', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'rev_pair'},{'id': '50', 'type': 'tuple', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '53', 'type': 'if_statement', 'children': ['54', '61']},{'id': '54', 'type': 'boolean_operator', 'children': ['55', '58'], 'value': 'and'},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'not'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'not'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'rev_pair'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '61', 'type': 'block', 'children': ['62', '72', '79', '86']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'compute_similarity_score'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'other_unit'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'rev_pair'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'all_scores'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'all_scores'},{'id': '96', 'type': 'list_comprehension', 'children': ['97', '98', '101']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '98', 'type': 'for_in_clause', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'all_scores'},{'id': '101', 'type': 'if_clause', 'children': ['102']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '!='},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'same_word_similarity'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '120']},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '113', 'type': 'binary_operator', 'children': ['114', '119'], 'value': '+'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '+'},{'id': '115', 'type': 'string', 'children': [], 'value': '"COLLECTION_"'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'current_similarity_measure'},{'id': '119', 'type': 'string', 'children': [], 'value': '"_pairwise_similarity_score_mean"'},{'id': '120', 'type': 'conditional_expression', 'children': ['121', '125', '126', '132'], 'value': 'if'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'get_mean'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'all_scores'},{'id': '125', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '131'], 'value': '>'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '131', 'type': 'integer', 'children': [], 'value': '0'},{'id': '132', 'type': 'string', 'children': [], 'value': "'NA'"}
def compute_pairwise_similarity_score(self): pairs = [] all_scores = [] for i, unit in enumerate(self.parsed_response): for j, other_unit in enumerate(self.parsed_response): if i != j: pair = (i, j) rev_pair = (j, i) if pair not in pairs and rev_pair not in pairs: score = self.compute_similarity_score(unit, other_unit) pairs.append(pair) pairs.append(rev_pair) all_scores.append(score) all_scores = [i for i in all_scores if i != self.same_word_similarity] self.measures["COLLECTION_" + self.current_similarity_measure + "_pairwise_similarity_score_mean"] = get_mean( all_scores) \ if len(pairs) > 0 else 'NA'
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute_between_collection_interval_duration'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '6', 'type': 'block', 'children': ['7', '11', '43', '73', '95', '117']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'collection_list'},{'id': '16', 'type': 'block', 'children': ['17', '25', '34']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '28', 'type': 'attribute', 'children': ['29', '33']},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '31', 'type': 'unary_operator', 'children': ['32'], 'value': '-'},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'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': 'durations'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'tuple', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'interstices'},{'id': '46', 'type': 'list_comprehension', 'children': ['47', '60']},{'id': '47', 'type': 'binary_operator', 'children': ['48', '55'], 'value': '-'},{'id': '48', 'type': 'subscript', 'children': ['49', '54']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '53', 'type': 'integer', 'children': [], 'value': '1'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'subscript', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'for_in_clause', 'children': ['61', '64']},{'id': '61', 'type': 'pattern_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '69', 'type': 'slice', 'children': ['70', '71']},{'id': '70', 'type': 'colon', 'children': []},{'id': '71', 'type': 'unary_operator', 'children': ['72'], 'value': '-'},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'id': '73', 'type': 'for_statement', 'children': ['74', '77', '81']},{'id': '74', 'type': 'pattern_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'interstices'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'if_statement', 'children': ['83', '88']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '87'], 'value': '<'},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'interstices'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '94']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'interstices'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '104']},{'id': '97', 'type': 'subscript', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '+'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '103', 'type': 'string', 'children': [], 'value': "'between_collection_interval_duration_mean'"},{'id': '104', 'type': 'conditional_expression', 'children': ['105', '109', '110', '116'], 'value': 'if'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'get_mean'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'interstices'},{'id': '109', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '115'], 'value': '>'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'interstices'},{'id': '115', 'type': 'integer', 'children': [], 'value': '0'},{'id': '116', 'type': 'string', 'children': [], 'value': "'NA'"},{'id': '117', 'type': 'if_statement', 'children': ['118', '122']},{'id': '118', 'type': 'not_operator', 'children': ['119']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '122', 'type': 'block', 'children': ['123', '125', '137', '189', '194', '196']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '125', 'type': 'print_statement', 'children': ['126']},{'id': '126', 'type': 'binary_operator', 'children': ['127', '136'], 'value': '+'},{'id': '127', 'type': 'binary_operator', 'children': ['128', '133'], 'value': '+'},{'id': '128', 'type': 'binary_operator', 'children': ['129', '132'], 'value': '+'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'current_similarity_measure'},{'id': '132', 'type': 'string', 'children': [], 'value': '" between-"'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'current_collection_type'},{'id': '136', 'type': 'string', 'children': [], 'value': '" durations"'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '140', 'type': 'binary_operator', 'children': ['141', '154', '155'], 'value': '+'},{'id': '141', 'type': 'list', 'children': ['142'], 'value': '[(self.current_collection_type + " 1 (start,end)", "Interval",\n self.current_collection_type + " 2 (start,end)")]'},{'id': '142', 'type': 'tuple', 'children': ['143', '148', '149']},{'id': '143', 'type': 'binary_operator', 'children': ['144', '147'], 'value': '+'},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'current_collection_type'},{'id': '147', 'type': 'string', 'children': [], 'value': '" 1 (start,end)"'},{'id': '148', 'type': 'string', 'children': [], 'value': '"Interval"'},{'id': '149', 'type': 'binary_operator', 'children': ['150', '153'], 'value': '+'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'current_collection_type'},{'id': '153', 'type': 'string', 'children': [], 'value': '" 2 (start,end)"'},{'id': '154', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '155', 'type': 'list_comprehension', 'children': ['156', '169']},{'id': '156', 'type': 'tuple', 'children': ['157', '161', '165']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'd1'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'i1'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'd2'},{'id': '169', 'type': 'for_in_clause', 'children': ['170', '174']},{'id': '170', 'type': 'pattern_list', 'children': ['171', '172', '173']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'd1'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'i1'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'd2'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '176', 'type': 'argument_list', 'children': ['177', '183', '184']},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '179', 'type': 'slice', 'children': ['180', '181']},{'id': '180', 'type': 'colon', 'children': []},{'id': '181', 'type': 'unary_operator', 'children': ['182'], 'value': '-'},{'id': '182', 'type': 'integer', 'children': [], 'value': '1'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'interstices'},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '186', 'type': 'slice', 'children': ['187', '188']},{'id': '187', 'type': 'integer', 'children': [], 'value': '1'},{'id': '188', 'type': 'colon', 'children': []},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'print_table'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '196', 'type': 'print_statement', 'children': ['197', '210', '211']},{'id': '197', 'type': 'binary_operator', 'children': ['198', '209'], 'value': '+'},{'id': '198', 'type': 'binary_operator', 'children': ['199', '206'], 'value': '+'},{'id': '199', 'type': 'binary_operator', 'children': ['200', '205'], 'value': '+'},{'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '+'},{'id': '201', 'type': 'string', 'children': [], 'value': '"Mean "'},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'current_similarity_measure'},{'id': '205', 'type': 'string', 'children': [], 'value': '" between-"'},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'current_collection_type'},{'id': '209', 'type': 'string', 'children': [], 'value': '" duration"'},{'id': '210', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '211', 'type': 'subscript', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '+'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '217', 'type': 'string', 'children': [], 'value': "'between_collection_interval_duration_mean'"}
def compute_between_collection_interval_duration(self, prefix): durations = [] for collection in self.collection_list: start = collection[0].start_time end = collection[-1].end_time durations.append((start, end)) interstices = [durations[i + 1][0] - durations[i][1] for i, d in enumerate(durations[:-1])] for i, entry in enumerate(interstices): if interstices[i] < 0: interstices[i] = 0 self.measures[prefix + 'between_collection_interval_duration_mean'] = get_mean(interstices) \ if len(interstices) > 0 else 'NA' if not self.quiet: print print self.current_similarity_measure + " between-" + self.current_collection_type + " durations" table = [(self.current_collection_type + " 1 (start,end)", "Interval", self.current_collection_type + " 2 (start,end)")] + \ [(str(d1), str(i1), str(d2)) for d1, i1, d2 in zip(durations[:-1], interstices, durations[1:])] print_table(table) print print "Mean " + self.current_similarity_measure + " between-" + self.current_collection_type + " duration", \ self.measures[prefix + 'between_collection_interval_duration_mean']
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute_within_collection_vowel_duration'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'no_singletons'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '27', '31', '87', '109']},{'id': '10', 'type': 'if_statement', 'children': ['11', '12', '17']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'no_singletons'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'min_size'},{'id': '16', 'type': 'integer', 'children': [], 'value': '2'},{'id': '17', 'type': 'else_clause', 'children': ['18']},{'id': '18', 'type': 'block', 'children': ['19', '23']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'augmented_assignment', 'children': ['21', '22'], 'value': '+='},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '22', 'type': 'string', 'children': [], 'value': '"no_singletons_"'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'min_size'},{'id': '26', 'type': 'integer', 'children': [], 'value': '1'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'for_statement', 'children': ['32', '33', '36']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'collection_list'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'if_statement', 'children': ['38', '44']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '43'], 'value': '>='},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'min_size'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'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': 'word'},{'id': '52', 'type': 'subscript', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'full_timed_response'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'index_in_timed_response'},{'id': '59', 'type': 'for_statement', 'children': ['60', '61', '64']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'phone'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'phones'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'if_statement', 'children': ['66', '73']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '70'], 'value': 'in'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'phone'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'vowels'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'binary_operator', 'children': ['81', '84'], 'value': '-'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'phone'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'phone'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '96']},{'id': '89', 'type': 'subscript', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '+'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '95', 'type': 'string', 'children': [], 'value': "'within_collection_vowel_duration_mean'"},{'id': '96', 'type': 'conditional_expression', 'children': ['97', '101', '102', '108'], 'value': 'if'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'get_mean'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'durations'},{'id': '101', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '107'], 'value': '>'},{'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': 'durations'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'string', 'children': [], 'value': "'NA'"},{'id': '109', 'type': 'if_statement', 'children': ['110', '114']},{'id': '110', 'type': 'not_operator', 'children': ['111']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'if_statement', 'children': ['116', '117', '140']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'no_singletons'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'print_statement', 'children': ['119', '132', '133']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '131'], 'value': '+'},{'id': '120', 'type': 'binary_operator', 'children': ['121', '128'], 'value': '+'},{'id': '121', 'type': 'binary_operator', 'children': ['122', '127'], 'value': '+'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '+'},{'id': '123', 'type': 'string', 'children': [], 'value': '"Mean within-"'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'current_similarity_measure'},{'id': '127', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'current_collection_type'},{'id': '131', 'type': 'string', 'children': [], 'value': '" vowel duration, excluding singletons:"'},{'id': '132', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '133', 'type': 'subscript', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '+'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '139', 'type': 'string', 'children': [], 'value': "'within_collection_vowel_duration_mean'"},{'id': '140', 'type': 'else_clause', 'children': ['141']},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'print_statement', 'children': ['143', '156', '157']},{'id': '143', 'type': 'binary_operator', 'children': ['144', '155'], 'value': '+'},{'id': '144', 'type': 'binary_operator', 'children': ['145', '152'], 'value': '+'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '151'], 'value': '+'},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '+'},{'id': '147', 'type': 'string', 'children': [], 'value': '"Mean within-"'},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'current_similarity_measure'},{'id': '151', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'current_collection_type'},{'id': '155', 'type': 'string', 'children': [], 'value': '" vowel duration, including singletons:"'},{'id': '156', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '157', 'type': 'subscript', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '+'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '163', 'type': 'string', 'children': [], 'value': "'within_collection_vowel_duration_mean'"}
def compute_within_collection_vowel_duration(self, prefix, no_singletons=False): if no_singletons: min_size = 2 else: prefix += "no_singletons_" min_size = 1 durations = [] for cluster in self.collection_list: if len(cluster) >= min_size: for word in cluster: word = self.full_timed_response[word.index_in_timed_response] for phone in word.phones: if phone.string in self.vowels: durations.append(phone.end - phone.start) self.measures[prefix + 'within_collection_vowel_duration_mean'] = get_mean(durations) \ if len(durations) > 0 else 'NA' if not self.quiet: if no_singletons: print "Mean within-" + self.current_similarity_measure + "-" + self.current_collection_type + \ " vowel duration, excluding singletons:", \ self.measures[prefix + 'within_collection_vowel_duration_mean'] else: print "Mean within-" + self.current_similarity_measure + "-" + self.current_collection_type + \ " vowel duration, including singletons:", \ self.measures[prefix + 'within_collection_vowel_duration_mean']
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_output'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '32', '181']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '=='},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'response_format'},{'id': '11', 'type': 'string', 'children': [], 'value': '"csv"'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '18']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'if_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'in'},{'id': '21', 'type': 'string', 'children': [], 'value': '"TIMING_"'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '31']},{'id': '26', 'type': 'subscript', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '31', 'type': 'string', 'children': [], 'value': '"NA"'},{'id': '32', 'type': 'if_statement', 'children': ['33', '37']},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '37', 'type': 'block', 'children': ['38', '40', '50', '64', '70', '72', '90', '104', '110', '112', '114', '132']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '40', 'type': 'print_statement', 'children': ['41']},{'id': '41', 'type': 'binary_operator', 'children': ['42', '49'], 'value': '+'},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'string', 'children': [], 'value': '" RESULTS:"'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '53', 'type': 'list_comprehension', 'children': ['54', '55', '60']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '55', 'type': 'for_in_clause', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '60', 'type': 'if_clause', 'children': ['61']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'},{'id': '62', 'type': 'string', 'children': [], 'value': "'COUNT_'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'e'},{'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': 'keys'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'print_statement', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': '"Counts:"'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'print_table'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'list_comprehension', 'children': ['77', '87']},{'id': '77', 'type': 'tuple', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'subscript', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '87', 'type': 'for_in_clause', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '93', 'type': 'list_comprehension', 'children': ['94', '95', '100']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '100', 'type': 'if_clause', 'children': ['101']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'in'},{'id': '102', 'type': 'string', 'children': [], 'value': "'COLLECTION_'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '112', 'type': 'print_statement', 'children': ['113']},{'id': '113', 'type': 'string', 'children': [], 'value': '"Collection measures:"'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'print_table'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'list_comprehension', 'children': ['119', '129']},{'id': '119', 'type': 'tuple', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'subscript', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '129', 'type': 'for_in_clause', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '132', 'type': 'if_statement', 'children': ['133', '138']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '137'], 'value': '=='},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'response_format'},{'id': '137', 'type': 'string', 'children': [], 'value': '"TextGrid"'},{'id': '138', 'type': 'block', 'children': ['139', '153', '159', '161', '163']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '142', 'type': 'list_comprehension', 'children': ['143', '144', '149']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '144', 'type': 'for_in_clause', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '149', 'type': 'if_clause', 'children': ['150']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': 'in'},{'id': '151', 'type': 'string', 'children': [], 'value': "'TIMING_'"},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'e'},{'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': 'keys'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '161', 'type': 'print_statement', 'children': ['162']},{'id': '162', 'type': 'string', 'children': [], 'value': '"Time-based measures:"'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'print_table'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'list_comprehension', 'children': ['168', '178']},{'id': '168', 'type': 'tuple', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'subscript', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '178', 'type': 'for_in_clause', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '181', 'type': 'if_statement', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'target_file'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'with_statement', 'children': ['187', '199']},{'id': '187', 'type': 'with_clause', 'children': ['188']},{'id': '188', 'type': 'with_item', 'children': ['189']},{'id': '189', 'type': 'as_pattern', 'children': ['190', '197']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '192', 'type': 'argument_list', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'target_file'},{'id': '196', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '197', 'type': 'as_pattern_target', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '199', 'type': 'block', 'children': ['200', '262', '276', '283']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '203', 'type': 'binary_operator', 'children': ['204', '244', '245'], 'value': '+'},{'id': '204', 'type': 'binary_operator', 'children': ['205', '226', '227'], 'value': '+'},{'id': '205', 'type': 'binary_operator', 'children': ['206', '208', '209'], 'value': '+'},{'id': '206', 'type': 'list', 'children': ['207'], 'value': "['file_id']"},{'id': '207', 'type': 'string', 'children': [], 'value': "'file_id'"},{'id': '208', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '209', 'type': 'list_comprehension', 'children': ['210', '217', '222']},{'id': '210', 'type': 'binary_operator', 'children': ['211', '216'], 'value': '+'},{'id': '211', 'type': 'binary_operator', 'children': ['212', '215'], 'value': '+'},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '215', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '217', 'type': 'for_in_clause', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '222', 'type': 'if_clause', 'children': ['223']},{'id': '223', 'type': 'comparison_operator', 'children': ['224', '225'], 'value': 'in'},{'id': '224', 'type': 'string', 'children': [], 'value': "'COUNT_'"},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '226', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '227', 'type': 'list_comprehension', 'children': ['228', '235', '240']},{'id': '228', 'type': 'binary_operator', 'children': ['229', '234'], 'value': '+'},{'id': '229', 'type': 'binary_operator', 'children': ['230', '233'], 'value': '+'},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '233', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '235', 'type': 'for_in_clause', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '240', 'type': 'if_clause', 'children': ['241']},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': 'in'},{'id': '242', 'type': 'string', 'children': [], 'value': "'COLLECTION_'"},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '244', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '245', 'type': 'list_comprehension', 'children': ['246', '253', '258']},{'id': '246', 'type': 'binary_operator', 'children': ['247', '252'], 'value': '+'},{'id': '247', 'type': 'binary_operator', 'children': ['248', '251'], 'value': '+'},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '251', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '253', 'type': 'for_in_clause', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '258', 'type': 'if_clause', 'children': ['259']},{'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': 'in'},{'id': '260', 'type': 'string', 'children': [], 'value': "'TIMING_'"},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'quoting'},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'QUOTE_MINIMAL'},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'writerow'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'call', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'writerow'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'binary_operator', 'children': ['290', '296'], 'value': '+'},{'id': '290', 'type': 'list', 'children': ['291'], 'value': '[self.measures["file_id"]]'},{'id': '291', 'type': 'subscript', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '295', 'type': 'string', 'children': [], 'value': '"file_id"'},{'id': '296', 'type': 'list_comprehension', 'children': ['297', '316']},{'id': '297', 'type': 'subscript', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'measures'},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'subscript', 'children': ['307', '313']},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '313', 'type': 'slice', 'children': ['314', '315']},{'id': '314', 'type': 'integer', 'children': [], 'value': '1'},{'id': '315', 'type': 'colon', 'children': []},{'id': '316', 'type': 'for_in_clause', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '318', 'type': 'subscript', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '320', 'type': 'slice', 'children': ['321', '322']},{'id': '321', 'type': 'integer', 'children': [], 'value': '1'},{'id': '322', 'type': 'colon', 'children': []}
def print_output(self): if self.response_format == "csv": for key in self.measures: if "TIMING_" in key: self.measures[key] = "NA" if not self.quiet: print print self.type.upper() + " RESULTS:" keys = [e for e in self.measures if 'COUNT_' in e] keys.sort() print "Counts:" print_table([(entry, str(self.measures[entry])) for entry in keys]) keys = [e for e in self.measures if 'COLLECTION_' in e] keys.sort() print print "Collection measures:" print_table([(entry, str(self.measures[entry])) for entry in keys]) if self.response_format == "TextGrid": keys = [e for e in self.measures if 'TIMING_' in e] keys.sort() print print "Time-based measures:" print_table([(entry, str(self.measures[entry])) for entry in keys]) if self.target_file: with open(self.target_file, 'w') as outfile: header = ['file_id'] + \ [self.type + "_" + e for e in self.measures if 'COUNT_' in e] + \ [self.type + "_" + e for e in self.measures if 'COLLECTION_' in e] + \ [self.type + "_" + e for e in self.measures if 'TIMING_' in e] writer = csv.writer(outfile, quoting=csv.QUOTE_MINIMAL) writer.writerow(header) writer.writerow([self.measures["file_id"]] + [self.measures["_".join(e.split('_')[1:])] for e in header[1:]])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fieldName'},{'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', '12']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'''\n sort_by - Return a copy of this collection, sorted by the given fieldName.\n The fieldName is accessed the same way as other filtering, so it supports custom properties, etc.\n @param fieldName <str> - The name of the field on which to sort by\n @param reverse <bool> Default False - If True, list will be in reverse order.\n @return <QueryableList> - A QueryableList of the same type with the elements sorted based on arguments.\n '''"},{'id': '12', 'type': 'return_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': '__class__'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22', '34']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '24', 'type': 'lambda', 'children': ['25', '27']},{'id': '25', 'type': 'lambda_parameters', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_get_item_value'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'fieldName'},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def sort_by(self, fieldName, reverse=False): ''' sort_by - Return a copy of this collection, sorted by the given fieldName. The fieldName is accessed the same way as other filtering, so it supports custom properties, etc. @param fieldName <str> - The name of the field on which to sort by @param reverse <bool> Default False - If True, list will be in reverse order. @return <QueryableList> - A QueryableList of the same type with the elements sorted based on arguments. ''' return self.__class__( sorted(self, key = lambda item : self._get_item_value(item, fieldName), reverse=reverse) )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_qtls_from_rqtl_data'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'lod_threshold'},{'id': '6', 'type': 'block', 'children': ['7', '18', '28', '189']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 't_matrix'},{'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': 'zip'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'list_splat', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'qtls'},{'id': '21', 'type': 'list', 'children': ['22'], 'value': "[['Trait', 'Linkage Group', 'Position', 'Exact marker', 'LOD']]"},{'id': '22', 'type': 'list', 'children': ['23', '24', '25', '26', '27'], 'value': "['Trait', 'Linkage Group', 'Position', 'Exact marker', 'LOD']"},{'id': '23', 'type': 'string', 'children': [], 'value': "'Trait'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'Linkage Group'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'Position'"},{'id': '26', 'type': 'string', 'children': [], 'value': "'Exact marker'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'LOD'"},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '35']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 't_matrix'},{'id': '32', 'type': 'slice', 'children': ['33', '34']},{'id': '33', 'type': 'integer', 'children': [], 'value': '3'},{'id': '34', 'type': 'colon', 'children': []},{'id': '35', 'type': 'block', 'children': ['36', '40', '44', '48', '52']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'lgroup'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'max_lod'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '47', 'type': 'None', 'children': []},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'while_statement', 'children': ['53', '59']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '<'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'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': 'row'},{'id': '59', 'type': 'block', 'children': ['60', '73', '183']},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'lgroup'},{'id': '63', 'type': 'None', 'children': []},{'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': 'lgroup'},{'id': '68', 'type': 'subscript', 'children': ['69', '72']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 't_matrix'},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '73', 'type': 'if_statement', 'children': ['74', '81', '122']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': '=='},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'lgroup'},{'id': '76', 'type': 'subscript', 'children': ['77', '80']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 't_matrix'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '81', 'type': 'block', 'children': ['82', '96']},{'id': '82', 'type': 'if_statement', 'children': ['83', '86']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'is'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'max_lod'},{'id': '85', 'type': 'None', 'children': []},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'max_lod'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '96', 'type': 'if_statement', 'children': ['97', '108']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '104'], 'value': '>'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'max_lod'},{'id': '108', 'type': 'block', 'children': ['109', '118']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'max_lod'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '122', 'type': 'else_clause', 'children': ['123']},{'id': '123', 'type': 'block', 'children': ['124', '171', '175', '179']},{'id': '124', 'type': 'if_statement', 'children': ['125', '140']},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '138', '139'], 'value': 'and'},{'id': '126', 'type': 'boolean_operator', 'children': ['127', '128', '129'], 'value': 'and'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'max_lod'},{'id': '128', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '134'], 'value': '>'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'max_lod'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'lod_threshold'},{'id': '138', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '140', 'type': 'block', 'children': ['141', '164']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '144', 'type': 'list', 'children': ['145', '148', '153', '158', '163'], 'value': '[row[0],\n t_matrix[1][peak],\n t_matrix[2][peak],\n t_matrix[0][peak],\n max_lod,\n ]'},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'subscript', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 't_matrix'},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '153', 'type': 'subscript', 'children': ['154', '157']},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 't_matrix'},{'id': '156', 'type': 'integer', 'children': [], 'value': '2'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '158', 'type': 'subscript', 'children': ['159', '162']},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 't_matrix'},{'id': '161', 'type': 'integer', 'children': [], 'value': '0'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'max_lod'},{'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': 'qtls'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'lgroup'},{'id': '174', 'type': 'None', 'children': []},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'max_lod'},{'id': '178', 'type': 'None', 'children': []},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'peak'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '+'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '188', 'type': 'integer', 'children': [], 'value': '1'},{'id': '189', 'type': 'return_statement', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'qtls'}
def get_qtls_from_rqtl_data(matrix, lod_threshold): t_matrix = list(zip(*matrix)) qtls = [['Trait', 'Linkage Group', 'Position', 'Exact marker', 'LOD']] for row in t_matrix[3:]: lgroup = None max_lod = None peak = None cnt = 1 while cnt < len(row): if lgroup is None: lgroup = t_matrix[1][cnt] if lgroup == t_matrix[1][cnt]: if max_lod is None: max_lod = float(row[cnt]) if float(row[cnt]) > float(max_lod): max_lod = float(row[cnt]) peak = cnt else: if max_lod \ and float(max_lod) > float(lod_threshold) \ and peak: qtl = [row[0], t_matrix[1][peak], t_matrix[2][peak], t_matrix[0][peak], max_lod, ] qtls.append(qtl) lgroup = None max_lod = None peak = cnt cnt = cnt + 1 return qtls
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'response'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '7', 'type': 'string', 'children': [], 'value': "''"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'last_modified'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'expires'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '19', 'type': 'block', 'children': ['20', '53', '67', '99', '128']},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25', '47']},{'id': '25', 'type': 'if_statement', 'children': ['26', '40']},{'id': '26', 'type': 'not_operator', 'children': ['27']},{'id': '27', 'type': '()', 'children': ['28']},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '34'], 'value': 'and'},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': '=='},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '32', 'type': 'integer', 'children': [], 'value': '0'},{'id': '33', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '39'], 'value': '=='},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '37', 'type': 'unary_operator', 'children': ['38'], 'value': '-'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'string', 'children': [], 'value': '\'"\''},{'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': 'etag'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '%'},{'id': '45', 'type': 'string', 'children': [], 'value': '\'"%s"\''},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '52']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '51', 'type': 'string', 'children': [], 'value': "'etag'"},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '53', 'type': 'if_statement', 'children': ['54', '57']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'last_modified'},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '63']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '62', 'type': 'string', 'children': [], 'value': "'last_modified'"},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'datetime_to_httpdate'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'last_modified'},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'expires'},{'id': '70', 'type': 'None', 'children': []},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'if_statement', 'children': ['73', '78', '88']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'expires'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '83', 'type': 'string', 'children': [], 'value': "'expires'"},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'datetime_to_httpdate'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'expires'},{'id': '88', 'type': 'else_clause', 'children': ['89']},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '95']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '94', 'type': 'string', 'children': [], 'value': "'expires'"},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'timedelta_to_httpdate'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'expires'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '102', 'type': 'list_comprehension', 'children': ['103', '116']},{'id': '103', 'type': 'tuple', 'children': ['104', '115']},{'id': '104', 'type': 'call', 'children': ['105', '114']},{'id': '105', 'type': 'attribute', 'children': ['106', '113']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '112', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '114', 'type': 'argument_list', 'children': []},{'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', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '127', 'type': 'argument_list', 'children': []},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'Response'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133', '134']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'body'}
def response(code, body='', etag=None, last_modified=None, expires=None, **kw): if etag is not None: if not (etag[0] == '"' and etag[-1] == '"'): etag = '"%s"' % etag kw['etag'] = etag if last_modified is not None: kw['last_modified'] = datetime_to_httpdate(last_modified) if expires is not None: if isinstance(expires, datetime): kw['expires'] = datetime_to_httpdate(expires) else: kw['expires'] = timedelta_to_httpdate(expires) headers = [(k.replace('_', '-').title(), v) for k, v in sorted(kw.items())] return Response(code, headers, body)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_optimum_prediction_fraction_correct_cutoffs_over_range'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'analysis_set'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'min_stability_classication_x_cutoff'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_stability_classication_x_cutoff'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'suppress_plot'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'analysis_file_prefix'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '20', '24', '28', '54', '59', '63', '67', '71', '75', '85', '153', '167', '176', '185', '194', '200', '209', '215', '226', '299']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'''Plots the optimum cutoff for the predictions to maximize the fraction correct metric over a range of experimental cutoffs.\n Returns the average scalar corresponding to the best value of fraction correct over a range of cutoff values for the experimental cutoffs.'''"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'analysis_set_prefix'},{'id': '23', 'type': 'string', 'children': [], 'value': "''"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'plot_filename'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'if_statement', 'children': ['29', '31']},{'id': '29', 'type': 'not_operator', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'suppress_plot'},{'id': '31', 'type': 'block', 'children': ['32', '42', '48']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'output_filename_prefix'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'{0}{1}optimum_fraction_correct_at_varying_kcal_mol'"},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'analysis_file_prefix'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'analysis_set_prefix'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'plot_filename'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '+'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'output_filename_prefix'},{'id': '47', 'type': 'string', 'children': [], 'value': "'.png'"},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'csv_filename'},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'output_filename_prefix'},{'id': '53', 'type': 'string', 'children': [], 'value': "'.txt'"},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '57', 'type': 'list', 'children': ['58'], 'value': "['ExperimentalCutoff,BestPredictionCutoff']"},{'id': '58', 'type': 'string', 'children': [], 'value': "'ExperimentalCutoff,BestPredictionCutoff'"},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'x_cutoff'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'min_stability_classication_x_cutoff'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'x_values'},{'id': '66', 'type': 'list', 'children': [], 'value': '[]'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'y_values'},{'id': '70', 'type': 'list', 'children': [], 'value': '[]'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'avg_scale'},{'id': '74', 'type': 'integer', 'children': [], 'value': '0'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'plot_graph'},{'id': '78', 'type': 'boolean_operator', 'children': ['79', '82'], 'value': 'and'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'generate_plots'},{'id': '82', 'type': 'not_operator', 'children': ['83']},{'id': '83', 'type': '()', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'suppress_plot'},{'id': '85', 'type': 'while_statement', 'children': ['86', '91']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '<'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'x_cutoff'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '+'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'max_stability_classication_x_cutoff'},{'id': '90', 'type': 'float', 'children': [], 'value': '0.1'},{'id': '91', 'type': 'block', 'children': ['92', '108', '129', '136', '143', '149']},{'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': 'max_value_cutoff'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'max_value'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'fraction_correct_range'},{'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': 'determine_optimum_fraction_correct_cutoffs'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104', '107']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'analysis_set'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'dataframe'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'x_cutoff'},{'id': '108', 'type': 'if_statement', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'plot_graph'},{'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': 'lines'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "','"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '126', 'type': 'tuple', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'x_cutoff'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'max_value_cutoff'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'x_values'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'x_cutoff'},{'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': 'y_values'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'max_value_cutoff'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'augmented_assignment', 'children': ['145', '146'], 'value': '+='},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'avg_scale'},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '/'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'max_value_cutoff'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'x_cutoff'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'augmented_assignment', 'children': ['151', '152'], 'value': '+='},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'x_cutoff'},{'id': '152', 'type': 'float', 'children': [], 'value': '0.1'},{'id': '153', 'type': 'if_statement', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'plot_graph'},{'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': 'write_file'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'csv_filename'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'avg_scale'},{'id': '170', 'type': 'binary_operator', 'children': ['171', '172'], 'value': '/'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'avg_scale'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'x_values'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'x_values'},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'x_values'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'y_values'},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'y_values'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'scalars'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '/'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'y_values'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'x_values'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'average_scalar'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'scalars'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'plot_label_1'},{'id': '212', 'type': 'binary_operator', 'children': ['213', '214'], 'value': '%'},{'id': '213', 'type': 'string', 'children': [], 'value': "'Scalar == %0.2f'"},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'average_scalar'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'plot_label_2'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '%'},{'id': '219', 'type': 'string', 'children': [], 'value': "'sigma == %0.2f'"},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'std'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'scalars'},{'id': '226', 'type': 'if_statement', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'plot_graph'},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'if_statement', 'children': ['230', '246']},{'id': '230', 'type': 'not_operator', 'children': ['231']},{'id': '231', 'type': '()', 'children': ['232']},{'id': '232', 'type': 'boolean_operator', 'children': ['233', '241'], 'value': 'and'},{'id': '233', 'type': 'call', 'children': ['234', '239']},{'id': '234', 'type': 'attribute', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'plot_filename'},{'id': '241', 'type': 'not_operator', 'children': ['242']},{'id': '242', 'type': '()', 'children': ['243']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'recreate_graphs'},{'id': '246', 'type': 'block', 'children': ['247', '268', '272', '284', '288']},{'id': '247', 'type': 'if_statement', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '249', 'type': 'block', 'children': ['250', '259']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '%'},{'id': '257', 'type': 'string', 'children': [], 'value': "'Saving scatterplot to %s.'"},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'plot_filename'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'binary_operator', 'children': ['266', '267'], 'value': '%'},{'id': '266', 'type': 'string', 'children': [], 'value': "'Saving plot of approximate optimal fraction correct cutoffs over varying experimental cutoffs to %s.'"},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'plot_filename'},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '271', 'type': 'string', 'children': [], 'value': "'Optimum cutoff for fraction correct metric at varying experimental cutoffs'"},{'id': '272', 'type': 'if_statement', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'analysis_set'},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'augmented_assignment', 'children': ['277', '278'], 'value': '+='},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'string', 'children': [], 'value': "' for {0}'"},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'analysis_set'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'r_script'},{'id': '287', 'type': 'string', 'children': [], 'value': '\'\'\'library(ggplot2)\nlibrary(gridExtra)\nlibrary(scales)\nlibrary(qualV)\npng(\'%(plot_filename)s\', height=4096, width=4096, bg="white", res=600)\nplot_data <- read.csv(\'%(csv_filename)s\', header=T)\nmax_y = max(plot_data$BestPredictionCutoff)\np <- ggplot(data = plot_data, aes(x = ExperimentalCutoff, y = BestPredictionCutoff)) +\n xlab("Experimental cutoff (kcal/mol)") +\n ylab("Optimal prediction cutoff (energy units)") +\n ggtitle("%(title)s") +\n geom_point() +\n geom_line() +\n geom_smooth() +\n geom_text(hjust=0, size=4, color="black", aes(0.5, max_y, fontface="plain", family = "sans", label="%(plot_label_1)s"), parse = T) +\n geom_text(hjust=0, size=4, color="black", aes(0.5, max_y - 0.5, fontface="plain", family = "sans", label="%(plot_label_2)s"), parse = T)\np\ndev.off()\'\'\''},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'RInterface'},{'id': '292', 'type': 'identifier', 'children': [], 'value': '_runRScript'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'binary_operator', 'children': ['295', '296'], 'value': '%'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'r_script'},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '298', 'type': 'argument_list', 'children': []},{'id': '299', 'type': 'return_statement', 'children': ['300']},{'id': '300', 'type': 'expression_list', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'average_scalar'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'plot_filename'}
def plot_optimum_prediction_fraction_correct_cutoffs_over_range(self, analysis_set, min_stability_classication_x_cutoff, max_stability_classication_x_cutoff, suppress_plot = False, analysis_file_prefix = None, verbose = True): '''Plots the optimum cutoff for the predictions to maximize the fraction correct metric over a range of experimental cutoffs. Returns the average scalar corresponding to the best value of fraction correct over a range of cutoff values for the experimental cutoffs.''' analysis_set_prefix = '' plot_filename = None if not suppress_plot: output_filename_prefix = '{0}{1}optimum_fraction_correct_at_varying_kcal_mol'.format(analysis_file_prefix, analysis_set_prefix) plot_filename = output_filename_prefix + '.png' csv_filename = output_filename_prefix + '.txt' lines = ['ExperimentalCutoff,BestPredictionCutoff'] x_cutoff = min_stability_classication_x_cutoff x_values = [] y_values = [] avg_scale = 0 plot_graph = self.generate_plots and not(suppress_plot) while x_cutoff < max_stability_classication_x_cutoff + 0.1: max_value_cutoff, max_value, fraction_correct_range = self.determine_optimum_fraction_correct_cutoffs(analysis_set, self.dataframe, x_cutoff) if plot_graph: lines.append(','.join(map(str, (x_cutoff, max_value_cutoff)))) x_values.append(x_cutoff) y_values.append(max_value_cutoff) avg_scale += max_value_cutoff / x_cutoff x_cutoff += 0.1 if plot_graph: write_file(csv_filename, '\n'.join(lines)) avg_scale = avg_scale / len(x_values) x_values = numpy.array(x_values) y_values = numpy.array(y_values) scalars = y_values / x_values average_scalar = numpy.mean(scalars) plot_label_1 = 'Scalar == %0.2f' % average_scalar plot_label_2 = 'sigma == %0.2f' % numpy.std(scalars) if plot_graph: if not(os.path.exists(plot_filename) and not(self.recreate_graphs)): if verbose: self.log('Saving scatterplot to %s.' % plot_filename) self.log('Saving plot of approximate optimal fraction correct cutoffs over varying experimental cutoffs to %s.' % plot_filename) title = 'Optimum cutoff for fraction correct metric at varying experimental cutoffs' if analysis_set: title += ' for {0}'.format(analysis_set) r_script = '''library(ggplot2) library(gridExtra) library(scales) library(qualV) png('%(plot_filename)s', height=4096, width=4096, bg="white", res=600) plot_data <- read.csv('%(csv_filename)s', header=T) max_y = max(plot_data$BestPredictionCutoff) p <- ggplot(data = plot_data, aes(x = ExperimentalCutoff, y = BestPredictionCutoff)) + xlab("Experimental cutoff (kcal/mol)") + ylab("Optimal prediction cutoff (energy units)") + ggtitle("%(title)s") + geom_point() + geom_line() + geom_smooth() + geom_text(hjust=0, size=4, color="black", aes(0.5, max_y, fontface="plain", family = "sans", label="%(plot_label_1)s"), parse = T) + geom_text(hjust=0, size=4, color="black", aes(0.5, max_y - 0.5, fontface="plain", family = "sans", label="%(plot_label_2)s"), parse = T) p dev.off()''' RInterface._runRScript(r_script % locals()) return average_scalar, plot_filename
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_chain_details_by_related_pdb_chains'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'pdb_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'chain_id'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'pfam_accs'},{'id': '8', 'type': 'block', 'children': ['9', '11', '17', '23', '31', '49', '53', '57', '122', '142', '165', '169', '174', '179', '189', '223', '233', '239', '249', '261', '279', '300', '315']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': "''' Returns a dict of SCOPe details using info\n This returns Pfam-level information for a PDB chain i.e. no details on the protein, species, or domain will be returned.\n If there are SCOPe entries for the associated Pfam accession numbers which agree then this function returns\n pretty complete information.\n '''"},{'id': '11', 'type': 'if_statement', 'children': ['12', '14']},{'id': '12', 'type': 'not_operator', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'pfam_accs'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'associated_pdb_chains'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'set'},{'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': 'pfam_api'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get_pfam_api'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'for_statement', 'children': ['32', '33', '34']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'pfam_acc'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'pfam_accs'},{'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': 'associated_pdb_chains'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'associated_pdb_chains'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'pfam_api'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_pdb_chains_from_pfam_accession_number'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'pfam_acc'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '52', 'type': 'list', 'children': [], 'value': '[]'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'pfam_scop_mapping'},{'id': '56', 'type': 'dictionary', 'children': []},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'pdb_chain_pair'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'associated_pdb_chains'},{'id': '60', 'type': 'block', 'children': ['61', '73', '91']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '66']},{'id': '63', 'type': 'pattern_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ass_pdb_id'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ass_chain_id'},{'id': '66', 'type': 'expression_list', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'pdb_chain_pair'},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'pdb_chain_pair'},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'get_chain_details'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82', '85', '88']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ass_pdb_id'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'ass_chain_id'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'internal_function_call'},{'id': '87', 'type': 'True', 'children': []},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'pfam_scop_mapping'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'pfam_scop_mapping'},{'id': '91', 'type': 'if_statement', 'children': ['92', '100']},{'id': '92', 'type': 'boolean_operator', 'children': ['93', '94'], 'value': 'and'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': "'chains'"},{'id': '100', 'type': 'block', 'children': ['101', '111']},{'id': '101', 'type': 'assert_statement', 'children': ['102']},{'id': '102', 'type': '()', 'children': ['103']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '110'], 'value': '=='},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '109', 'type': 'string', 'children': [], 'value': "'chains'"},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'hits'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'subscript', 'children': ['118', '121']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '120', 'type': 'string', 'children': [], 'value': "'chains'"},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ass_chain_id'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'allowed_scop_domains'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '129', 'type': 'subscript', 'children': ['130', '141']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '132', 'type': 'argument_list', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'pfam_scop_mapping'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '140', 'type': 'argument_list', 'children': []},{'id': '141', 'type': 'integer', 'children': [], 'value': '0'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'allowed_scop_domains'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'binary_operator', 'children': ['152', '156'], 'value': '+'},{'id': '152', 'type': '()', 'children': ['153']},{'id': '153', 'type': 'boolean_operator', 'children': ['154', '155'], 'value': 'or'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'allowed_scop_domains'},{'id': '155', 'type': 'list', 'children': [], 'value': '[]'},{'id': '156', 'type': '()', 'children': ['157']},{'id': '157', 'type': 'boolean_operator', 'children': ['158', '164'], 'value': 'or'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'get_sunid_for_pfam_accs'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'pfam_accs'},{'id': '164', 'type': 'list', 'children': [], 'value': '[]'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'filtered_hits'},{'id': '168', 'type': 'list', 'children': [], 'value': '[]'},{'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']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'pfam_accs'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'allowed_scop_domains'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '%'},{'id': '184', 'type': 'string', 'children': [], 'value': "'%d hits'"},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '189', 'type': 'for_statement', 'children': ['190', '191', '192']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '192', 'type': 'block', 'children': ['193', '197']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'domains_to_ignore'},{'id': '196', 'type': 'list', 'children': [], 'value': '[]'},{'id': '197', 'type': 'for_statement', 'children': ['198', '201', '208']},{'id': '198', 'type': 'pattern_list', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '201', 'type': 'call', 'children': ['202', '207']},{'id': '202', 'type': 'attribute', 'children': ['203', '206']},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '205', 'type': 'string', 'children': [], 'value': "'domains'"},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'if_statement', 'children': ['210', '215']},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '214'], 'value': 'in'},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '213', 'type': 'string', 'children': [], 'value': "'sunid'"},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'allowed_scop_domains'},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'filtered_hits'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '%'},{'id': '228', 'type': 'string', 'children': [], 'value': "'%d filtered_hits'"},{'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': 'filtered_hits'},{'id': '233', 'type': 'if_statement', 'children': ['234', '236']},{'id': '234', 'type': 'not_operator', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'filtered_hits'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': 'None', 'children': []},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'get_basic_pdb_chain_information'},{'id': '246', 'type': 'argument_list', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'pdb_id'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'chain_id'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'get_common_fields'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'filtered_hits'},{'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': 'd'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '269', 'type': 'argument_list', 'children': ['270', '273', '276']},{'id': '270', 'type': 'keyword_argument', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'SCOPe_sources'},{'id': '272', 'type': 'string', 'children': [], 'value': "'Pfam + SCOPe'"},{'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'SCOPe_search_fields'},{'id': '275', 'type': 'string', 'children': [], 'value': "'Pfam + link_pdb.pdb_chain_id'"},{'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'SCOPe_trust_level'},{'id': '278', 'type': 'integer', 'children': [], 'value': '3'},{'id': '279', 'type': 'for_statement', 'children': ['280', '283', '293']},{'id': '280', 'type': 'pattern_list', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '292']},{'id': '287', 'type': 'attribute', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'levels'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '292', 'type': 'argument_list', 'children': []},{'id': '293', 'type': 'block', 'children': ['294']},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '299']},{'id': '296', 'type': 'subscript', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '299', 'type': 'None', 'children': []},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'call', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'get_common_hierarchy'},{'id': '313', 'type': 'argument_list', 'children': ['314']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'filtered_hits'},{'id': '315', 'type': 'return_statement', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'd'}
def get_chain_details_by_related_pdb_chains(self, pdb_id, chain_id, pfam_accs): ''' Returns a dict of SCOPe details using info This returns Pfam-level information for a PDB chain i.e. no details on the protein, species, or domain will be returned. If there are SCOPe entries for the associated Pfam accession numbers which agree then this function returns pretty complete information. ''' if not pfam_accs: return None associated_pdb_chains = set() pfam_api = self.get_pfam_api() for pfam_acc in pfam_accs: associated_pdb_chains = associated_pdb_chains.union(pfam_api.get_pdb_chains_from_pfam_accession_number(pfam_acc)) hits = [] pfam_scop_mapping = {} for pdb_chain_pair in associated_pdb_chains: ass_pdb_id, ass_chain_id = pdb_chain_pair[0], pdb_chain_pair[1] hit = self.get_chain_details(ass_pdb_id, chain = ass_chain_id, internal_function_call = True, pfam_scop_mapping = pfam_scop_mapping) if hit and hit.get('chains'): assert(len(hit['chains']) == 1) hits.append(hit['chains'][ass_chain_id]) allowed_scop_domains = map(int, map(set.intersection, pfam_scop_mapping.values())[0]) allowed_scop_domains = list(set((allowed_scop_domains or []) + (self.get_sunid_for_pfam_accs(pfam_accs) or []))) filtered_hits = [] print(pfam_accs) print(allowed_scop_domains) print('%d hits' % len(hits)) for hit in hits: domains_to_ignore = [] for k, v in hit['domains'].iteritems(): if v['sunid'] in allowed_scop_domains: filtered_hits.append(v) print('%d filtered_hits' % len(filtered_hits)) if not filtered_hits: return None d = self.get_basic_pdb_chain_information(pdb_id, chain_id) d.update(self.get_common_fields(filtered_hits)) d.update(dict( SCOPe_sources = 'Pfam + SCOPe', SCOPe_search_fields = 'Pfam + link_pdb.pdb_chain_id', SCOPe_trust_level = 3 )) for k, v in sorted(self.levels.iteritems()): d[v] = None d.update(dict(self.get_common_hierarchy(filtered_hits))) return d
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'recall_service'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '6', 'type': 'block', 'children': ['7', '20', '41', '211']},{'id': '7', 'type': 'if_statement', 'children': ['8', '14']},{'id': '8', 'type': 'not_operator', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Service'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'raise_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': '"service must be of type Service."'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'string', 'children': [], 'value': '"The deployment for {0} on {1} failed starting the rollback."'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '30', 'type': 'argument_list', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'alias'},{'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': 'url'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'geturl'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'function_definition', 'children': ['42', '43', '45']},{'id': '42', 'type': 'function_name', 'children': [], 'value': 'anonymous'},{'id': '43', 'type': 'parameters', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'anonymous_service'},{'id': '45', 'type': 'block', 'children': ['46', '59', '68']},{'id': '46', 'type': 'if_statement', 'children': ['47', '53']},{'id': '47', 'type': 'not_operator', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'anonymous_service'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'Service'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'raise_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'string', 'children': [], 'value': '"service must be an instance of Service."'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'containers'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'find_previous_service_containers'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'anonymous_service'},{'id': '68', 'type': 'if_statement', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'containers'},{'id': '70', 'type': 'block', 'children': ['71', '90', '98']},{'id': '71', 'type': 'for_statement', 'children': ['72', '73', '83']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'anonymous_service'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'containers'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'delete_statement', 'children': ['85']},{'id': '85', 'type': 'subscript', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'anonymous_service'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'containers'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '97']},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'anonymous_service'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'cargo'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'for_statement', 'children': ['99', '102', '108']},{'id': '99', 'type': 'pattern_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'containers'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'if_statement', 'children': ['110', '120', '139']},{'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': 'container'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': "'running'"},{'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': 'logger'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': '"is already running... Might want to investigate."'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '130', 'type': 'dictionary', 'children': ['131', '134']},{'id': '131', 'type': 'pair', 'children': ['132', '133']},{'id': '132', 'type': 'string', 'children': [], 'value': "'formatter'"},{'id': '133', 'type': 'string', 'children': [], 'value': "'container'"},{'id': '134', 'type': 'pair', 'children': ['135', '136']},{'id': '135', 'type': 'string', 'children': [], 'value': "'container'"},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '139', 'type': 'else_clause', 'children': ['140']},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'if_statement', 'children': ['142', '147', '166']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '146', 'type': 'argument_list', 'children': []},{'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': 'logger'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155']},{'id': '154', 'type': 'string', 'children': [], 'value': '"is restarted and healthy."'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '157', 'type': 'dictionary', 'children': ['158', '161']},{'id': '158', 'type': 'pair', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': "'formatter'"},{'id': '160', 'type': 'string', 'children': [], 'value': "'container'"},{'id': '161', 'type': 'pair', 'children': ['162', '163']},{'id': '162', 'type': 'string', 'children': [], 'value': "'container'"},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168', '186', '192']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'string', 'children': [], 'value': '"failed to start."'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '177', 'type': 'dictionary', 'children': ['178', '181']},{'id': '178', 'type': 'pair', 'children': ['179', '180']},{'id': '179', 'type': 'string', 'children': [], 'value': "'formatter'"},{'id': '180', 'type': 'string', 'children': [], 'value': "'container'"},{'id': '181', 'type': 'pair', 'children': ['182', '183']},{'id': '182', 'type': 'string', 'children': [], 'value': "'container'"},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'dump_logs'},{'id': '191', 'type': 'argument_list', 'children': []},{'id': '192', 'type': 'raise_statement', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'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': '"The deployment for {0} on {1} went horribly wrong"'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '200', 'type': 'argument_list', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'url'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'geturl'},{'id': '210', 'type': 'argument_list', 'children': []},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': '_service_map'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218', '219']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'anonymous'},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'descending'},{'id': '221', 'type': 'False', 'children': []}
def recall_service(self, service): if not isinstance(service, Service): raise TypeError("service must be of type Service.") logger.warning("The deployment for {0} on {1} failed starting the rollback.".format(service.alias, self.url.geturl())) def anonymous(anonymous_service): if not isinstance(anonymous_service, Service): raise TypeError("service must be an instance of Service.") containers = self.find_previous_service_containers(anonymous_service) if containers: for name in list(anonymous_service.containers.keys()): del anonymous_service.containers[name] anonymous_service.cargo.delete() for name, container in six.iteritems(containers): if container.state().get('running'): logger.info( "is already running... Might want to investigate.", extra={'formatter': 'container', 'container': container.name} ) else: if container.start(): logger.info( "is restarted and healthy.", extra={'formatter': 'container', 'container': container.name} ) else: logger.error( "failed to start.", extra={'formatter': 'container', 'container': container.name} ) container.dump_logs() raise Exception( "The deployment for {0} on {1} went horribly wrong".format(container.name, self.url.geturl()) ) self._service_map(service, anonymous, descending=False)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_items'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'identifier', 'children': [], 'value': '__identity'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '24']},{'id': '12', 'type': 'function_definition', 'children': ['13', '14', '16']},{'id': '13', 'type': 'function_name', 'children': [], 'value': 'pairkey_key'},{'id': '14', 'type': 'parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28', '33', '36']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'pairkey_key'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def sorted_items(d, key=__identity, reverse=False): def pairkey_key(item): return key(item[0]) return sorted(d.items(), key=pairkey_key, reverse=reverse)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_or_create_in_transaction'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tsession'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'missing_columns'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'variable_columns'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'updatable_columns'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'only_use_supplied_columns'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'read_only'},{'id': '21', 'type': 'False', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '25', '34', '52', '63', '74', '90', '178', '182', '213', '228', '242', '250']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': '\'\'\'\n Uses the SQLAlchemy model to retrieve an existing record based on the supplied field values or, if there is no\n existing record, to create a new database record.\n :param tsession: An SQLAlchemy transactioned session\n :param model: The name of the SQLAlchemy class representing the table\n :param values: A dict of values which will be used to populate the fields of the model\n :param missing_columns: Elements of missing_columns are expected to be fields in the model but are left blank regardless of whether they exist in values. This is useful for auto_increment fields.\n :param updatable_columns: If these are specified, they are treated as missing columns in the record matching and if a record is found, these fields will be updated\n :param variable_columns: If these are specified, they are treated as missing columns in the record matching but are not updated. A good use of these are for datetime fields which default to the current datetime\n :param read_only: If this is set then we query the database and return an instance if one exists but we do not create a new record.\n :return:\n Note: This function is a convenience function and is NOT efficient. The "tsession.query(model).filter_by(**pruned_values)"\n call is only (sometimes) efficient if an index exists on the keys of pruned_values. If any of the fields of pruned_values are\n large (even if otherwise deferred/loaded lazily) then you will incur a performance hit on lookup. You may need\n to reconsider any calls to this function in inner loops of your code.\'\'\''},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'fieldnames'},{'id': '37', 'type': 'list_comprehension', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'attribute', 'children': ['47', '51']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sqlalchemy_inspect'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'missing_columns'},{'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': 'fieldnames'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '63', 'type': 'for_statement', 'children': ['64', '65', '66']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'updatable_columns'},{'id': '66', 'type': 'block', 'children': ['67']},{'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': 'fieldnames'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '74', 'type': 'for_statement', 'children': ['75', '76', '77']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'variable_columns'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'if_statement', 'children': ['79', '82']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'in'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'fieldnames'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'fieldnames'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '90', 'type': 'if_statement', 'children': ['91', '92', '115']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'only_use_supplied_columns'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'fieldnames'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '106']},{'id': '100', 'type': 'attribute', 'children': ['101', '105']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'fieldnames'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'else_clause', 'children': ['116']},{'id': '116', 'type': 'block', 'children': ['117', '152']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'unexpected_fields'},{'id': '120', 'type': 'call', 'children': ['121', '147']},{'id': '121', 'type': 'attribute', 'children': ['122', '146']},{'id': '122', 'type': 'call', 'children': ['123', '141']},{'id': '123', 'type': 'attribute', 'children': ['124', '140']},{'id': '124', 'type': 'call', 'children': ['125', '135']},{'id': '125', 'type': 'attribute', 'children': ['126', '134']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'fieldnames'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'variable_columns'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'updatable_columns'},{'id': '152', 'type': 'if_statement', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'unexpected_fields'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'raise_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'string', 'children': [], 'value': '"The fields \'{0}\' were passed but not found in the schema for table {1}."'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '163', 'type': 'argument_list', 'children': ['164', '173']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'string', 'children': [], 'value': '"\', \'"'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'unexpected_fields'},{'id': '173', 'type': 'subscript', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '176', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '177', 'type': 'string', 'children': [], 'value': "'__tablename__'"},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'pruned_values'},{'id': '181', 'type': 'dictionary', 'children': []},{'id': '182', 'type': 'for_statement', 'children': ['183', '184', '200']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '184', 'type': 'call', 'children': ['185', '195']},{'id': '185', 'type': 'attribute', 'children': ['186', '194']},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'fieldnames'},{'id': '200', 'type': 'block', 'children': ['201', '207']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'k'},{'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': 'pruned_values'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '216', 'type': 'call', 'children': ['217', '225']},{'id': '217', 'type': 'attribute', 'children': ['218', '224']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'tsession'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'filter_by'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'dictionary_splat', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'pruned_values'},{'id': '228', 'type': 'if_statement', 'children': ['229', '236']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '235'], 'value': '>'},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '234', 'type': 'argument_list', 'children': []},{'id': '235', 'type': 'integer', 'children': [], 'value': '1'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'raise_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'string', 'children': [], 'value': "'Multiple records were found with the search criteria.'"},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '249', 'type': 'argument_list', 'children': []},{'id': '250', 'type': 'if_statement', 'children': ['251', '252', '279']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '252', 'type': 'block', 'children': ['253', '277']},{'id': '253', 'type': 'if_statement', 'children': ['254', '257']},{'id': '254', 'type': 'comparison_operator', 'children': ['255', '256'], 'value': '=='},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'read_only'},{'id': '256', 'type': 'False', 'children': []},{'id': '257', 'type': 'block', 'children': ['258', '271']},{'id': '258', 'type': 'for_statement', 'children': ['259', '260', '261']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'updatable_columns'},{'id': '261', 'type': 'block', 'children': ['262']},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '265', 'type': 'argument_list', 'children': ['266', '267', '268']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'tsession'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '276', 'type': 'argument_list', 'children': []},{'id': '277', 'type': 'return_statement', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '279', 'type': 'else_clause', 'children': ['280']},{'id': '280', 'type': 'block', 'children': ['281', '346']},{'id': '281', 'type': 'if_statement', 'children': ['282', '285']},{'id': '282', 'type': 'comparison_operator', 'children': ['283', '284'], 'value': '=='},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'read_only'},{'id': '284', 'type': 'False', 'children': []},{'id': '285', 'type': 'block', 'children': ['286', '323', '331', '338', '344']},{'id': '286', 'type': 'if_statement', 'children': ['287', '300']},{'id': '287', 'type': 'comparison_operator', 'children': ['288', '296'], 'value': '!='},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'pruned_values'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '295', 'type': 'argument_list', 'children': []},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'fieldnames'},{'id': '300', 'type': 'block', 'children': ['301']},{'id': '301', 'type': 'raise_statement', 'children': ['302']},{'id': '302', 'type': 'call', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'string', 'children': [], 'value': "'Some required fields are missing: {0}. Either supply these fields or add them to the missing_columns list.'"},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '317']},{'id': '311', 'type': 'attribute', 'children': ['312', '316']},{'id': '312', 'type': 'call', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'fieldnames'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '317', 'type': 'argument_list', 'children': ['318']},{'id': '318', 'type': 'call', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'pruned_values'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '322', 'type': 'argument_list', 'children': []},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'assignment', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '326', 'type': 'call', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'dictionary_splat', 'children': ['330']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'pruned_values'},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'call', 'children': ['333', '336']},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'tsession'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'call', 'children': ['340', '343']},{'id': '340', 'type': 'attribute', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'tsession'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '343', 'type': 'argument_list', 'children': []},{'id': '344', 'type': 'return_statement', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '346', 'type': 'return_statement', 'children': ['347']},{'id': '347', 'type': 'None', 'children': []}
def get_or_create_in_transaction(tsession, model, values, missing_columns = [], variable_columns = [], updatable_columns = [], only_use_supplied_columns = False, read_only = False): ''' Uses the SQLAlchemy model to retrieve an existing record based on the supplied field values or, if there is no existing record, to create a new database record. :param tsession: An SQLAlchemy transactioned session :param model: The name of the SQLAlchemy class representing the table :param values: A dict of values which will be used to populate the fields of the model :param missing_columns: Elements of missing_columns are expected to be fields in the model but are left blank regardless of whether they exist in values. This is useful for auto_increment fields. :param updatable_columns: If these are specified, they are treated as missing columns in the record matching and if a record is found, these fields will be updated :param variable_columns: If these are specified, they are treated as missing columns in the record matching but are not updated. A good use of these are for datetime fields which default to the current datetime :param read_only: If this is set then we query the database and return an instance if one exists but we do not create a new record. :return: Note: This function is a convenience function and is NOT efficient. The "tsession.query(model).filter_by(**pruned_values)" call is only (sometimes) efficient if an index exists on the keys of pruned_values. If any of the fields of pruned_values are large (even if otherwise deferred/loaded lazily) then you will incur a performance hit on lookup. You may need to reconsider any calls to this function in inner loops of your code.''' values = copy.deepcopy(values) fieldnames = [c.name for c in list(sqlalchemy_inspect(model).columns)] for c in missing_columns: fieldnames.remove(c) for c in updatable_columns: fieldnames.remove(c) for c in variable_columns: if c in fieldnames: fieldnames.remove(c) if only_use_supplied_columns: fieldnames = sorted(set(fieldnames).intersection(set(values.keys()))) else: unexpected_fields = set(values.keys()).difference(set(fieldnames)).difference(set(variable_columns)).difference(set(updatable_columns)) if unexpected_fields: raise Exception("The fields '{0}' were passed but not found in the schema for table {1}.".format("', '".join(sorted(unexpected_fields)), model.__dict__['__tablename__'])) pruned_values = {} for k in set(values.keys()).intersection(set(fieldnames)): v = values[k] pruned_values[k] = v instance = tsession.query(model).filter_by(**pruned_values) if instance.count() > 1: raise Exception('Multiple records were found with the search criteria.') instance = instance.first() if instance: if read_only == False: for c in updatable_columns: setattr(instance, c, values[c]) tsession.flush() return instance else: if read_only == False: if sorted(pruned_values.keys()) != sorted(fieldnames): raise Exception('Some required fields are missing: {0}. Either supply these fields or add them to the missing_columns list.'.format(set(fieldnames).difference(pruned_values.keys()))) instance = model(**pruned_values) tsession.add(instance) tsession.flush() return instance return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'errors'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13', '21', '82', '181']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '10', 'type': 'argument_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_validate'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '21', 'type': 'elif_clause', 'children': ['22', '29']},{'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': 'instance'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'forms'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'BaseForm'},{'id': '29', 'type': 'block', 'children': ['30', '50']},{'id': '30', 'type': 'if_statement', 'children': ['31', '40']},{'id': '31', 'type': 'boolean_operator', 'children': ['32', '35'], 'value': 'and'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'is_bound'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'is_valid'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'return_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': '_validate'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'},{'id': '50', 'type': 'return_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': '_validate'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'list_comprehension', 'children': ['60', '77']},{'id': '60', 'type': 'tuple', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'f'},{'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': 'instance'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'for_in_clause', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'validators'},{'id': '82', 'type': 'elif_clause', 'children': ['83', '90']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'formsets'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'BaseFormSet'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'if_statement', 'children': ['92', '95', '148']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'can_delete'},{'id': '95', 'type': 'block', 'children': ['96', '137']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'validate_forms'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '115'], 'value': '+'},{'id': '100', 'type': 'list_comprehension', 'children': ['101', '102', '107']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '102', 'type': 'for_in_clause', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'initial_forms'},{'id': '107', 'type': 'if_clause', 'children': ['108']},{'id': '108', 'type': 'not_operator', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_should_delete_form'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '115', 'type': 'list_comprehension', 'children': ['116', '117', '122']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '117', 'type': 'for_in_clause', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'extra_forms'},{'id': '122', 'type': 'if_clause', 'children': ['123']},{'id': '123', 'type': '()', 'children': ['124']},{'id': '124', 'type': 'boolean_operator', 'children': ['125', '130'], 'value': 'and'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'has_changed'},{'id': '129', 'type': 'argument_list', 'children': []},{'id': '130', 'type': 'not_operator', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '134', 'type': 'identifier', 'children': [], 'value': '_should_delete_form'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '137', 'type': 'return_statement', 'children': ['138']},{'id': '138', 'type': 'list_comprehension', 'children': ['139', '145']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '145', 'type': 'for_in_clause', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'validate_forms'},{'id': '148', 'type': 'else_clause', 'children': ['149']},{'id': '149', 'type': 'block', 'children': ['150', '170']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'validate_forms'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '157'], 'value': '+'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'initial_forms'},{'id': '157', 'type': 'list_comprehension', 'children': ['158', '159', '164']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '159', 'type': 'for_in_clause', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'extra_forms'},{'id': '164', 'type': 'if_clause', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'has_changed'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'return_statement', 'children': ['171']},{'id': '171', 'type': 'list_comprehension', 'children': ['172', '178']},{'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': 'errors'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '178', 'type': 'for_in_clause', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'validate_forms'},{'id': '181', 'type': 'elif_clause', 'children': ['182', '189']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'Model'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'return_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': '_validate'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'list_comprehension', 'children': ['200', '207']},{'id': '200', 'type': 'tuple', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '207', 'type': 'for_in_clause', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'validators'}
def errors(self, instance): if isinstance(instance, dict): return self._validate(instance) elif isinstance(instance, forms.BaseForm): if instance.is_bound and instance.is_valid(): return self._validate(instance.cleaned_data) return self._validate(dict( [ (f, instance.initial.get(f, instance[f].value())) for f in self.validators ] )) elif isinstance(instance, formsets.BaseFormSet): if instance.can_delete: validate_forms = [ form for form in instance.initial_forms if not instance._should_delete_form(form) ] + [ form for form in instance.extra_forms if (form.has_changed() and not instance._should_delete_form(form)) ] return [ self.errors(f) for f in validate_forms ] else: validate_forms = instance.initial_forms + [ form for form in instance.extra_forms if form.has_changed() ] return [self.errors(f) for f in validate_forms] elif isinstance(instance, models.Model): return self._validate(dict( [(f, getattr(instance, f)) for f in self.validators] ))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'multimatch'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'include_ids'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '23', '25', '44', '63', '82', '219']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': "'''\n Iterator over relationship IDs that match a pattern of components, with multiple options provided for each component\n origin - (optional) origin of the relationship (similar to an RDF subject), or set of values. If omitted any origin will be matched.\n rel - (optional) type IRI of the relationship (similar to an RDF predicate), or set of values. If omitted any relationship will be matched.\n target - (optional) target of the relationship (similar to an RDF object), a boolean, floating point or unicode object, or set of values. If omitted any target will be matched.\n attrs - (optional) attribute mapping of relationship metadata, i.e. {attrname1: attrval1, attrname2: attrval2}. If any attribute is specified, an exact match is made (i.e. the attribute name and value must match).\n include_ids - If true include statement IDs with yield values\n '''"},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '28', 'type': 'conditional_expression', 'children': ['29', '30', '39'], 'value': 'if'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '30', 'type': 'boolean_operator', 'children': ['31', '34'], 'value': 'or'},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'list', 'children': ['43'], 'value': '[origin]'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '47', 'type': 'conditional_expression', 'children': ['48', '49', '58'], 'value': 'if'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '53'], 'value': 'or'},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'list', 'children': ['62'], 'value': '[rel]'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '66', 'type': 'conditional_expression', 'children': ['67', '68', '77'], 'value': 'if'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '68', 'type': 'boolean_operator', 'children': ['69', '72'], 'value': 'or'},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '71', 'type': 'None', 'children': []},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'list', 'children': ['81'], 'value': '[target]'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '82', 'type': 'for_statement', 'children': ['83', '86', '92']},{'id': '83', 'type': 'pattern_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': '_relationships'},{'id': '92', 'type': 'block', 'children': ['93', '97', '110', '123', '136', '171']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '96', 'type': 'True', 'children': []},{'id': '97', 'type': 'if_statement', 'children': ['98', '105']},{'id': '98', 'type': 'boolean_operator', 'children': ['99', '100'], 'value': 'and'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': 'not'},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'ORIGIN'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'origin'},{'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': 'matches'},{'id': '109', 'type': 'False', 'children': []},{'id': '110', 'type': 'if_statement', 'children': ['111', '118']},{'id': '111', 'type': 'boolean_operator', 'children': ['112', '113'], 'value': 'and'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '117'], 'value': 'not'},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'RELATIONSHIP'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '122', 'type': 'False', 'children': []},{'id': '123', 'type': 'if_statement', 'children': ['124', '131']},{'id': '124', 'type': 'boolean_operator', 'children': ['125', '126'], 'value': 'and'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': 'not'},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'TARGET'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'target'},{'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': 'matches'},{'id': '135', 'type': 'False', 'children': []},{'id': '136', 'type': 'if_statement', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'for_statement', 'children': ['140', '143', '148']},{'id': '140', 'type': 'pattern_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'if_statement', 'children': ['150', '166']},{'id': '150', 'type': 'boolean_operator', 'children': ['151', '156'], 'value': 'or'},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'not'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'ATTRIBUTES'},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '165'], 'value': '!='},{'id': '157', 'type': 'call', 'children': ['158', '163']},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ATTRIBUTES'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '170', 'type': 'False', 'children': []},{'id': '171', 'type': 'if_statement', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'if_statement', 'children': ['175', '176', '198']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'include_ids'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'yield', 'children': ['179']},{'id': '179', 'type': 'expression_list', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '181', 'type': 'tuple', 'children': ['182', '185', '188', '191']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '184', 'type': 'integer', 'children': [], 'value': '0'},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '187', 'type': 'integer', 'children': [], 'value': '1'},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '190', 'type': 'integer', 'children': [], 'value': '2'},{'id': '191', 'type': 'call', 'children': ['192', '197']},{'id': '192', 'type': 'attribute', 'children': ['193', '196']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '195', 'type': 'integer', 'children': [], 'value': '3'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'else_clause', 'children': ['199']},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'yield', 'children': ['202']},{'id': '202', 'type': 'tuple', 'children': ['203', '206', '209', '212']},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '205', 'type': 'integer', 'children': [], 'value': '0'},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '208', 'type': 'integer', 'children': [], 'value': '1'},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '211', 'type': 'integer', 'children': [], 'value': '2'},{'id': '212', 'type': 'call', 'children': ['213', '218']},{'id': '213', 'type': 'attribute', 'children': ['214', '217']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'curr_rel'},{'id': '216', 'type': 'integer', 'children': [], 'value': '3'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '218', 'type': 'argument_list', 'children': []},{'id': '219', 'type': 'return_statement', 'children': []}
def multimatch(self, origin=None, rel=None, target=None, attrs=None, include_ids=False): ''' Iterator over relationship IDs that match a pattern of components, with multiple options provided for each component origin - (optional) origin of the relationship (similar to an RDF subject), or set of values. If omitted any origin will be matched. rel - (optional) type IRI of the relationship (similar to an RDF predicate), or set of values. If omitted any relationship will be matched. target - (optional) target of the relationship (similar to an RDF object), a boolean, floating point or unicode object, or set of values. If omitted any target will be matched. attrs - (optional) attribute mapping of relationship metadata, i.e. {attrname1: attrval1, attrname2: attrval2}. If any attribute is specified, an exact match is made (i.e. the attribute name and value must match). include_ids - If true include statement IDs with yield values ''' raise NotImplementedError origin = origin if origin is None or isinstance(origin, set) else set([origin]) rel = rel if rel is None or isinstance(rel, set) else set([rel]) target = target if target is None or isinstance(target, set) else set([target]) for index, curr_rel in enumerate(self._relationships): matches = True if origin and curr_rel[ORIGIN] not in origin: matches = False if rel and curr_rel[RELATIONSHIP] not in rel: matches = False if target and curr_rel[TARGET] not in target: matches = False if attrs: for k, v in attrs.items(): if k not in curr_rel[ATTRIBUTES] or curr_rel[ATTRIBUTES].get(k) != v: matches = False if matches: if include_ids: yield index, (curr_rel[0], curr_rel[1], curr_rel[2], curr_rel[3].copy()) else: yield (curr_rel[0], curr_rel[1], curr_rel[2], curr_rel[3].copy()) return
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_qtls_from_mapqtl_data'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'inputfile'},{'id': '7', 'type': 'block', 'children': ['8', '27', '31', '35', '136', '167']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'trait_name'},{'id': '11', 'type': 'subscript', 'children': ['12', '26']},{'id': '12', 'type': 'call', 'children': ['13', '24']},{'id': '13', 'type': 'attribute', 'children': ['14', '23']},{'id': '14', 'type': 'subscript', 'children': ['15', '22']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'inputfile'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': "')_'"},{'id': '21', 'type': 'integer', 'children': [], 'value': '1'},{'id': '22', 'type': 'integer', 'children': [], 'value': '1'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'.mqo'"},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'qtls'},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '42']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '39', 'type': 'slice', 'children': ['40', '41']},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'colon', 'children': []},{'id': '42', 'type': 'block', 'children': ['43', '52', '91', '104', '117']},{'id': '43', 'type': 'if_statement', 'children': ['44', '47']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '52', 'type': 'if_statement', 'children': ['53', '60']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': '!='},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '56', 'type': 'integer', 'children': [], 'value': '1'},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'block', 'children': ['61', '87']},{'id': '61', 'type': 'if_statement', 'children': ['62', '73']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '69'], 'value': '>'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '68', 'type': 'integer', 'children': [], 'value': '4'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '73', 'type': 'block', 'children': ['74', '80']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'trait_name'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'qtls'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '91', 'type': 'if_statement', 'children': ['92', '97']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': '=='},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '95', 'type': 'integer', 'children': [], 'value': '4'},{'id': '96', 'type': 'string', 'children': [], 'value': "''"},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '103']},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '102', 'type': 'integer', 'children': [], 'value': '4'},{'id': '103', 'type': 'integer', 'children': [], 'value': '0'},{'id': '104', 'type': 'if_statement', 'children': ['105', '110']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '109'], 'value': '=='},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '108', 'type': 'integer', 'children': [], 'value': '4'},{'id': '109', 'type': 'string', 'children': [], 'value': "''"},{'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': 'qtl'},{'id': '115', 'type': 'integer', 'children': [], 'value': '4'},{'id': '116', 'type': 'integer', 'children': [], 'value': '0'},{'id': '117', 'type': 'if_statement', 'children': ['118', '131']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '125'], 'value': '>'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '124', 'type': 'integer', 'children': [], 'value': '4'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '130', 'type': 'integer', 'children': [], 'value': '4'},{'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': 'qtl'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '136', 'type': 'if_statement', 'children': ['137', '148']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '144'], 'value': '>'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '143', 'type': 'integer', 'children': [], 'value': '4'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '148', 'type': 'block', 'children': ['149', '155']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '154']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '153', 'type': 'integer', 'children': [], 'value': '0'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'trait_name'},{'id': '155', 'type': 'if_statement', 'children': ['156', '159']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'not'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'qtls'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'qtls'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'qtl'},{'id': '167', 'type': 'return_statement', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'qtls'}
def get_qtls_from_mapqtl_data(matrix, threshold, inputfile): trait_name = inputfile.split(')_', 1)[1].split('.mqo')[0] qtls = [] qtl = None for entry in matrix[1:]: if qtl is None: qtl = entry if qtl[1] != entry[1]: if float(qtl[4]) > float(threshold): qtl[0] = trait_name qtls.append(qtl) qtl = entry if entry[4] == '': entry[4] = 0 if qtl[4] == '': qtl[4] = 0 if float(entry[4]) > float(qtl[4]): qtl = entry if float(qtl[4]) > float(threshold): qtl[0] = trait_name if qtl not in qtls: qtls.append(qtl) return qtls
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_range_pairs'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'prs'},{'id': '5', 'type': 'block', 'children': ['6', '8', '12', '23', '30', '34', '38', '144']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''Takes in a list of pairs specifying ranges and returns a sorted list of merged, sorted ranges.'''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'new_prs'},{'id': '11', 'type': 'list', 'children': [], 'value': '[]'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sprs'},{'id': '15', 'type': 'list_comprehension', 'children': ['16', '20']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '20', 'type': 'for_in_clause', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'prs'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sprs'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sprs'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'merged'},{'id': '33', 'type': 'False', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'while_statement', 'children': ['39', '45']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '<'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sprs'},{'id': '45', 'type': 'block', 'children': ['46', '52', '61', '128', '140']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'newx'},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '+'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'new_pair'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sprs'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '61', 'type': 'for_statement', 'children': ['62', '63', '73']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '65', 'type': 'argument_list', 'children': ['66', '69']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '+'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sprs'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'if_statement', 'children': ['75', '89']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '79', '86'], 'value': '<='},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'new_pair'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '85'], 'value': '-'},{'id': '80', 'type': 'subscript', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sprs'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '84', 'type': 'integer', 'children': [], 'value': '0'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'new_pair'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'block', 'children': ['90', '106', '122']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '95']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'new_pair'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '97', 'type': 'argument_list', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'new_pair'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'subscript', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sprs'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '105', 'type': 'integer', 'children': [], 'value': '0'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'new_pair'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '113', 'type': 'argument_list', 'children': ['114', '117']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'new_pair'},{'id': '116', 'type': 'integer', 'children': [], 'value': '1'},{'id': '117', 'type': 'subscript', 'children': ['118', '121']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'sprs'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'newx'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '+'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'if_statement', 'children': ['129', '132']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'not'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'new_pair'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'new_prs'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'new_prs'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'new_pair'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'newx'},{'id': '144', 'type': 'return_statement', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'new_prs'}
def merge_range_pairs(prs): '''Takes in a list of pairs specifying ranges and returns a sorted list of merged, sorted ranges.''' new_prs = [] sprs = [sorted(p) for p in prs] sprs = sorted(sprs) merged = False x = 0 while x < len(sprs): newx = x + 1 new_pair = list(sprs[x]) for y in range(x + 1, len(sprs)): if new_pair[0] <= sprs[y][0] - 1 <= new_pair[1]: new_pair[0] = min(new_pair[0], sprs[y][0]) new_pair[1] = max(new_pair[1], sprs[y][1]) newx = y + 1 if new_pair not in new_prs: new_prs.append(new_pair) x = newx return new_prs
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'agent_cls'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'n_agents'},{'id': '10', 'type': 'integer', 'children': [], 'value': '10'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'agent_kwargs'},{'id': '13', 'type': 'dictionary', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'env_cls'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'Environment'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'env_kwargs'},{'id': '19', 'type': 'dictionary', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'conns'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'log_folder'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'block', 'children': ['30', '52', '69', '126', '136', '140', '225', '239']},{'id': '30', 'type': 'if_statement', 'children': ['31', '37']},{'id': '31', 'type': 'not_operator', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'env_cls'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'Environment'},{'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': 'TypeError'},{'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': '"Environment class must be derived from ({}"'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'Environment'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '51', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '52', 'type': 'if_statement', 'children': ['53', '63']},{'id': '53', 'type': 'boolean_operator', 'children': ['54', '57'], 'value': 'and'},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'not_operator', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '62', 'type': 'string', 'children': [], 'value': "'__call__'"},{'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': 'TypeError'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': '"Callback must be callable."'},{'id': '69', 'type': 'if_statement', 'children': ['70', '75', '102']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'agent_cls'},{'id': '74', 'type': 'string', 'children': [], 'value': "'__iter__'"},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'for_statement', 'children': ['77', '78', '79']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'agent_cls'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'if_statement', 'children': ['81', '87']},{'id': '81', 'type': 'not_operator', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'CreativeAgent'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'raise_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': '"All agent classes must be derived from {}"'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'attribute', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'CreativeAgent'},{'id': '100', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '102', 'type': 'else_clause', 'children': ['103']},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'if_statement', 'children': ['105', '111']},{'id': '105', 'type': 'not_operator', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'agent_cls'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'CreativeAgent'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'raise_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'string', 'children': [], 'value': '"Agent class must be derived from {}"'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'CreativeAgent'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '125', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'env_cls'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'create'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'dictionary_splat', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'env_kwargs'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '139', 'type': 'list', 'children': [], 'value': '[]'},{'id': '140', 'type': 'if_statement', 'children': ['141', '146', '196']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'agent_cls'},{'id': '145', 'type': 'string', 'children': [], 'value': "'__iter__'"},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'for_statement', 'children': ['148', '149', '156']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'n_agents'},{'id': '156', 'type': 'block', 'children': ['157', '165', '173']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '164']},{'id': '159', 'type': 'subscript', 'children': ['160', '163']},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'agent_kwargs'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '163', 'type': 'string', 'children': [], 'value': "'environment'"},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '172']},{'id': '167', 'type': 'subscript', 'children': ['168', '171']},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'agent_kwargs'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '171', 'type': 'string', 'children': [], 'value': "'log_folder'"},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'log_folder'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '+'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '178', 'type': 'list_comprehension', 'children': ['179', '188']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'agent_cls'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'dictionary_splat', 'children': ['185']},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'agent_kwargs'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '188', 'type': 'for_in_clause', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'n_agents'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '196', 'type': 'else_clause', 'children': ['197']},{'id': '197', 'type': 'block', 'children': ['198', '204', '210']},{'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': 'agent_kwargs'},{'id': '202', 'type': 'string', 'children': [], 'value': "'environment'"},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '209']},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'agent_kwargs'},{'id': '208', 'type': 'string', 'children': [], 'value': "'log_folder'"},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'log_folder'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '213', 'type': 'list_comprehension', 'children': ['214', '219']},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'agent_cls'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'dictionary_splat', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'agent_kwargs'},{'id': '219', 'type': 'for_in_clause', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'n_agents'},{'id': '225', 'type': 'if_statement', 'children': ['226', '229']},{'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': '>'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'conns'},{'id': '228', 'type': 'integer', 'children': [], 'value': '0'},{'id': '229', 'type': 'block', 'children': ['230']},{'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': 'env'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'create_random_connections'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'keyword_argument', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'conns'},{'id': '239', 'type': 'return_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'Simulation'},{'id': '242', 'type': 'argument_list', 'children': ['243', '244', '245']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'log_folder'}
def create(self, agent_cls=None, n_agents=10, agent_kwargs={}, env_cls=Environment, env_kwargs={}, callback=None, conns=0, log_folder=None): if not issubclass(env_cls, Environment): raise TypeError("Environment class must be derived from ({}" .format(Environment.__class__.__name__)) if callback is not None and not hasattr(callback, '__call__'): raise TypeError("Callback must be callable.") if hasattr(agent_cls, '__iter__'): for e in agent_cls: if not issubclass(e, CreativeAgent): raise TypeError("All agent classes must be derived from {}" .format(CreativeAgent.__class__.__name__)) else: if not issubclass(agent_cls, CreativeAgent): raise TypeError("Agent class must be derived from {}" .format(CreativeAgent.__class__.__name__)) env = env_cls.create(**env_kwargs) agents = [] if hasattr(agent_cls, '__iter__'): for i in range(len(n_agents)): agent_kwargs[i]['environment'] = env agent_kwargs[i]['log_folder'] = log_folder agents = agents + [agent_cls[i](**agent_kwargs[i]) for e in range(n_agents[i])] else: agent_kwargs['environment'] = env agent_kwargs['log_folder'] = log_folder agents = [agent_cls(**agent_kwargs) for e in range(n_agents)] if conns > 0: env.create_random_connections(n=conns) return Simulation(env, callback, log_folder)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'callproc'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'procname'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '8', 'type': 'tuple', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'expect_return_value'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '22', '26', '30', '34', '38', '89', '105', '122', '272', '322']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'augmented_assignment', 'children': ['18', '21'], 'value': '+='},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'procedures_run'},{'id': '21', 'type': 'integer', 'children': [], 'value': '1'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'errcode'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'caughte'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'out_param_indices'},{'id': '37', 'type': 'list', 'children': [], 'value': '[]'},{'id': '38', 'type': 'for_statement', 'children': ['39', '40', '47']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '47', 'type': 'block', 'children': ['48', '54']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '54', 'type': 'if_statement', 'children': ['55', '70']},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '65'], 'value': 'and'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '61'], 'value': '=='},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': "''"},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': '=='},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '68', 'type': 'integer', 'children': [], 'value': '0'},{'id': '69', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '70', 'type': 'block', 'children': ['71', '82']},{'id': '71', 'type': 'assert_statement', 'children': ['72']},{'id': '72', 'type': '()', 'children': ['73']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '80'], 'value': '=='},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': "' '"},{'id': '80', 'type': 'unary_operator', 'children': ['81'], 'value': '-'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'out_param_indices'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '89', 'type': 'if_statement', 'children': ['90', '97']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'not'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'procname'},{'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': 'list_stored_procedures'},{'id': '96', 'type': 'argument_list', 'children': []},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'raise_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '%'},{'id': '103', 'type': 'string', 'children': [], 'value': '"The stored procedure \'%s\' does not exist."'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'procname'},{'id': '105', 'type': 'if_statement', 'children': ['106', '114']},{'id': '106', 'type': 'not_operator', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': '"^\\s*\\w+\\s*$"'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'procname'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'raise_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '%'},{'id': '120', 'type': 'string', 'children': [], 'value': '"Expected a stored procedure name in callproc but received \'%s\'."'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'procname'},{'id': '122', 'type': 'while_statement', 'children': ['123', '128']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '<'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'numTries'},{'id': '128', 'type': 'block', 'children': ['129', '133']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'augmented_assignment', 'children': ['131', '132'], 'value': '+='},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'try_statement', 'children': ['134', '234', '257']},{'id': '134', 'type': 'block', 'children': ['135', '141', '151', '167', '177', '188', '194', '198', '232']},{'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': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': '_get_connection'},{'id': '140', 'type': 'argument_list', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '144', 'type': 'call', 'children': ['145', '150']},{'id': '145', 'type': 'attribute', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '150', 'type': 'argument_list', 'children': []},{'id': '151', 'type': 'if_statement', 'children': ['152', '161']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '157'], 'value': '!='},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'tuple', 'children': []},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '165', 'type': 'tuple', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'errcode'},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'callproc'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'procname'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'lastrowid'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'lastrowid'},{'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': 'cursor'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'out_param_results'},{'id': '197', 'type': 'list', 'children': [], 'value': '[]'},{'id': '198', 'type': 'if_statement', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'out_param_indices'},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'out_param_results'},{'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': 'execute'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '%'},{'id': '210', 'type': 'string', 'children': [], 'value': "'SELECT %s'"},{'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': 'list_comprehension', 'children': ['217', '229']},{'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '%'},{'id': '218', 'type': 'string', 'children': [], 'value': "'@_%s_%d AS %s'"},{'id': '219', 'type': 'tuple', 'children': ['220', '221', '222']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'procname'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'pindex'},{'id': '222', 'type': 'subscript', 'children': ['223', '226']},{'id': '223', 'type': 'subscript', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'pindex'},{'id': '226', 'type': 'slice', 'children': ['227', '228']},{'id': '227', 'type': 'integer', 'children': [], 'value': '1'},{'id': '228', 'type': 'colon', 'children': []},{'id': '229', 'type': 'for_in_clause', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'pindex'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'out_param_indices'},{'id': '232', 'type': 'return_statement', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'out_param_results'},{'id': '234', 'type': 'except_clause', 'children': ['235', '238', '239']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'MySQLdb'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'OperationalError'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '239', 'type': 'block', 'children': ['240', '246', '252', '256']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '244', 'type': 'identifier', 'children': [], 'value': '_close_connection'},{'id': '245', 'type': 'argument_list', 'children': []},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'errcode'},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'e'},{'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': 'caughte'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '256', 'type': 'continue_statement', 'children': []},{'id': '257', 'type': 'except_clause', 'children': ['258']},{'id': '258', 'type': 'block', 'children': ['259', '265', '271']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '263', 'type': 'identifier', 'children': [], 'value': '_close_connection'},{'id': '264', 'type': 'argument_list', 'children': []},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'traceback'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'print_exc'},{'id': '270', 'type': 'argument_list', 'children': []},{'id': '271', 'type': 'break_statement', 'children': []},{'id': '272', 'type': 'if_statement', 'children': ['273', '275']},{'id': '273', 'type': 'not_operator', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '275', 'type': 'block', 'children': ['276', '298', '314']},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '283']},{'id': '278', 'type': 'attribute', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'binary_operator', 'children': ['285', '286'], 'value': '%'},{'id': '285', 'type': 'string', 'children': [], 'value': '"\\nSQL execution error call stored procedure %s at %s:"'},{'id': '286', 'type': 'tuple', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'procname'},{'id': '288', 'type': 'call', 'children': ['289', '296']},{'id': '289', 'type': 'attribute', 'children': ['290', '295']},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '294', 'type': 'argument_list', 'children': []},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'string', 'children': [], 'value': '"%Y-%m-%d %H:%M:%S"'},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '305']},{'id': '300', 'type': 'attribute', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'binary_operator', 'children': ['307', '308'], 'value': '%'},{'id': '307', 'type': 'string', 'children': [], 'value': '"\\nErrorcode/Error: %d - \'%s\'.\\n"'},{'id': '308', 'type': 'tuple', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'errcode'},{'id': '310', 'type': 'call', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'caughte'},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '321']},{'id': '316', 'type': 'attribute', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '321', 'type': 'argument_list', 'children': []},{'id': '322', 'type': 'raise_statement', 'children': ['323']},{'id': '323', 'type': 'call', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'MySQLdb'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'OperationalError'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'caughte'}
def callproc(self, procname, parameters=(), quiet=False, expect_return_value=False): self.procedures_run += 1 i = 0 errcode = 0 caughte = None out_param_indices = [] for j in range(len(parameters)): p = parameters[j] if type(p) == type('') and p[0] == '@': assert(p.find(' ') == -1) out_param_indices.append(j) if procname not in self.list_stored_procedures(): raise Exception("The stored procedure '%s' does not exist." % procname) if not re.match("^\s*\w+\s*$", procname): raise Exception("Expected a stored procedure name in callproc but received '%s'." % procname) while i < self.numTries: i += 1 try: self._get_connection() cursor = self.connection.cursor() if type(parameters) != type(()): parameters = (parameters,) errcode = cursor.callproc(procname, parameters) self.lastrowid = int(cursor.lastrowid) cursor.close() out_param_results = [] if out_param_indices: out_param_results = self.execute('SELECT %s' % ", ".join(['@_%s_%d AS %s' % (procname, pindex, parameters[pindex][1:]) for pindex in out_param_indices])) return out_param_results except MySQLdb.OperationalError, e: self._close_connection() errcode = e[0] caughte = e continue except: self._close_connection() traceback.print_exc() break if not quiet: sys.stderr.write("\nSQL execution error call stored procedure %s at %s:" % ( procname, datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) sys.stderr.write("\nErrorcode/Error: %d - '%s'.\n" % (errcode, str(caughte))) sys.stderr.flush() raise MySQLdb.OperationalError(caughte)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_insert_dict_string'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tblname'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'PKfields'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'check_existing'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '19', '35', '51', '55', '59']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "'''The main function of the insert_dict functions.\n This creates and returns the SQL query and parameters used by the other functions but does not insert any data into the database.\n Simple function for inserting a dictionary whose keys match the fieldnames of tblname. The function returns two values, the\n second of which is a dict containing the primary keys of the record. If a record already exists then no insertion is performed and\n (False, the dictionary of existing primary keys) is returned. Otherwise, the record is inserted into the database and (True, d)\n is returned.'''"},{'id': '19', 'type': 'if_statement', 'children': ['20', '29']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '=='},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'PKfields'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': '""'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'PKfields'},{'id': '33', 'type': 'list', 'children': ['34'], 'value': '[PKfields]'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'PKfields'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '=='},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'SQL'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'try_statement', 'children': ['60', '207']},{'id': '60', 'type': 'block', 'children': ['61', '65', '69', '109', '117', '125', '129', '162', '189', '202']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'wherestr'},{'id': '64', 'type': 'list', 'children': [], 'value': '[]'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'PKvalues'},{'id': '68', 'type': 'list', 'children': [], 'value': '[]'},{'id': '69', 'type': 'for_statement', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'PKfield'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'PKfields'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'if_statement', 'children': ['74', '79', '89']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '=='},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'PKfield'},{'id': '78', 'type': 'None', 'children': []},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'wherestr'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '%'},{'id': '87', 'type': 'string', 'children': [], 'value': '"%s IS NULL"'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'PKfield'},{'id': '89', 'type': 'else_clause', 'children': ['90']},{'id': '90', 'type': 'block', 'children': ['91', '100']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'wherestr'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '%'},{'id': '98', 'type': 'string', 'children': [], 'value': '"%s=%%s"'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'PKfield'},{'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': 'PKvalues'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'PKfield'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'PKfields'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'PKfields'},{'id': '116', 'type': 'string', 'children': [], 'value': '","'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'wherestr'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'wherestr'},{'id': '124', 'type': 'string', 'children': [], 'value': '" AND "'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'record_exists'},{'id': '128', 'type': 'None', 'children': []},{'id': '129', 'type': 'if_statement', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'check_existing'},{'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': 'record_exists'},{'id': '135', 'type': 'not_operator', 'children': ['136']},{'id': '136', 'type': '()', 'children': ['137']},{'id': '137', 'type': 'not_operator', 'children': ['138']},{'id': '138', 'type': '()', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'execute_select'},{'id': '143', 'type': 'argument_list', 'children': ['144', '153', '159']},{'id': '144', 'type': 'binary_operator', 'children': ['145', '150'], 'value': '+'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '%'},{'id': '146', 'type': 'string', 'children': [], 'value': '"SELECT %s FROM %s"'},{'id': '147', 'type': 'tuple', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'PKfields'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'tblname'},{'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '%'},{'id': '151', 'type': 'string', 'children': [], 'value': '" WHERE %s"'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'wherestr'},{'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'PKvalues'},{'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '161', 'type': 'False', 'children': []},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'SQL'},{'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '%'},{'id': '166', 'type': 'string', 'children': [], 'value': "'INSERT INTO %s (%s) VALUES (%s)'"},{'id': '167', 'type': 'tuple', 'children': ['168', '169', '174']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'tblname'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '173', 'type': 'string', 'children': [], 'value': '", "'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '176', 'type': 'argument_list', 'children': ['177', '188']},{'id': '177', 'type': 'list_comprehension', 'children': ['178', '179']},{'id': '178', 'type': 'string', 'children': [], 'value': "'%s'"},{'id': '179', 'type': 'for_in_clause', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '188', 'type': 'string', 'children': [], 'value': "','"},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'list_comprehension', 'children': ['196', '199']},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '199', 'type': 'for_in_clause', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '202', 'type': 'return_statement', 'children': ['203']},{'id': '203', 'type': 'expression_list', 'children': ['204', '205', '206']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'SQL'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'record_exists'},{'id': '207', 'type': 'except_clause', 'children': ['208', '209', '210']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'raise_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '%'},{'id': '216', 'type': 'string', 'children': [], 'value': '"Error occurred during database insertion: \'%s\'. %s"'},{'id': '217', 'type': 'tuple', 'children': ['218', '222']},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'traceback'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'format_exc'},{'id': '226', 'type': 'argument_list', 'children': []}
def create_insert_dict_string(self, tblname, d, PKfields=[], fields=None, check_existing = False): '''The main function of the insert_dict functions. This creates and returns the SQL query and parameters used by the other functions but does not insert any data into the database. Simple function for inserting a dictionary whose keys match the fieldnames of tblname. The function returns two values, the second of which is a dict containing the primary keys of the record. If a record already exists then no insertion is performed and (False, the dictionary of existing primary keys) is returned. Otherwise, the record is inserted into the database and (True, d) is returned.''' if type(PKfields) == type(""): PKfields = [PKfields] if fields == None: fields = sorted(d.keys()) values = None SQL = None try: wherestr = [] PKvalues = [] for PKfield in PKfields: if d[PKfield] == None: wherestr.append("%s IS NULL" % PKfield) else: wherestr.append("%s=%%s" % PKfield) PKvalues.append(d[PKfield]) PKfields = join(PKfields, ",") wherestr = join(wherestr, " AND ") record_exists = None if check_existing: record_exists = not(not(self.execute_select("SELECT %s FROM %s" % (PKfields, tblname) + " WHERE %s" % wherestr, parameters=tuple(PKvalues), locked = False))) SQL = 'INSERT INTO %s (%s) VALUES (%s)' % ( tblname, join(fields, ", "), join(['%s' for x in range(len(fields))], ',')) values = tuple([d[k] for k in fields]) return SQL, values, record_exists except Exception, e: raise Exception("Error occurred during database insertion: '%s'. %s" % (str(e), traceback.format_exc()))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fixed_point'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'is_zero'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'plus'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'minus'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '9', 'type': 'block', 'children': ['10', '55']},{'id': '10', 'type': 'decorated_definition', 'children': ['11', '13']},{'id': '11', 'type': 'decorator', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'memo_Y'},{'id': '13', 'type': 'function_definition', 'children': ['14', '15', '17']},{'id': '14', 'type': 'function_name', 'children': [], 'value': '_fixed_point'},{'id': '15', 'type': 'parameters', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'fixed_point_fun'},{'id': '17', 'type': 'block', 'children': ['18', '53']},{'id': '18', 'type': 'function_definition', 'children': ['19', '20', '23']},{'id': '19', 'type': 'function_name', 'children': [], 'value': '__fixed_point'},{'id': '20', 'type': 'parameters', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'collected'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'new'},{'id': '23', 'type': 'block', 'children': ['24', '32', '40']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'minus'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'new'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'collected'},{'id': '32', 'type': 'if_statement', 'children': ['33', '37']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'is_zero'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'collected'},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'fixed_point_fun'},{'id': '43', 'type': 'argument_list', 'children': ['44', '49']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'plus'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'collected'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': '__fixed_point'},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_fixed_point'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'x'}
def fixed_point(is_zero, plus, minus, f, x): @memo_Y def _fixed_point(fixed_point_fun): def __fixed_point(collected, new): diff = minus(new, collected) if is_zero(diff): return collected return fixed_point_fun(plus(collected, diff), f(diff)) return __fixed_point return _fixed_point(x, f(x))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'connections_from_graph'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'edge_data'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '29', '42', '53', '84', '91', '97', '105']},{'id': '10', 'type': 'if_statement', 'children': ['11', '21']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '14', 'type': 'argument_list', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '18', 'type': 'tuple', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'Graph'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'DiGraph'},{'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': 'TypeError'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'concatenated_string', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': '"Graph structure must be derived from Networkx\'s "'},{'id': '28', 'type': 'string', 'children': [], 'value': '"Graph or DiGraph."'},{'id': '29', 'type': 'if_statement', 'children': ['30', '36']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '35', 'type': 'string', 'children': [], 'value': "'get_agents'"},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'raise_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'string', 'children': [], 'value': '"Parameter \'env\' must have get_agents."'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'addrs'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_agents'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'addr'},{'id': '52', 'type': 'True', 'children': []},{'id': '53', 'type': 'if_statement', 'children': ['54', '63']},{'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': 'addrs'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'G'},{'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': 'call', 'children': ['69', '75']},{'id': '69', 'type': 'attribute', 'children': ['70', '74']},{'id': '70', 'type': 'concatenated_string', 'children': ['71', '72', '73']},{'id': '71', 'type': 'string', 'children': [], 'value': '"The number of graph nodes and agents in the "'},{'id': '72', 'type': 'string', 'children': [], 'value': '"environment (excluding the manager agent) must "'},{'id': '73', 'type': 'string', 'children': [], 'value': '"match. Now got {} nodes and {} agents."'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '75', 'type': 'argument_list', 'children': ['76', '80']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'addrs'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'addrs'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort_addrs'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'addrs'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_addrs2nodes'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'addrs'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'conn_map'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_edges2conns'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'edge_data'},{'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': 'env'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'create_connections'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'conn_map'}
def connections_from_graph(env, G, edge_data=False): if not issubclass(G.__class__, (Graph, DiGraph)): raise TypeError("Graph structure must be derived from Networkx's " "Graph or DiGraph.") if not hasattr(env, 'get_agents'): raise TypeError("Parameter 'env' must have get_agents.") addrs = env.get_agents(addr=True) if len(addrs) != len(G): raise ValueError("The number of graph nodes and agents in the " "environment (excluding the manager agent) must " "match. Now got {} nodes and {} agents." .format(len(G), len(addrs))) addrs = sort_addrs(addrs) _addrs2nodes(addrs, G) conn_map = _edges2conns(G, edge_data) env.create_connections(conn_map)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'graph_from_connections'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'directed'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '20', '31', '83']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '12', 'type': 'conditional_expression', 'children': ['13', '16', '17'], 'value': 'if'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'DiGraph'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'directed'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Graph'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'conn_list'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_connections'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '30', 'type': 'True', 'children': []},{'id': '31', 'type': 'for_statement', 'children': ['32', '35', '36']},{'id': '32', 'type': 'pattern_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'conns'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'conn_list'},{'id': '36', 'type': 'block', 'children': ['37', '44', '48', '68']},{'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': 'G'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ebunch'},{'id': '47', 'type': 'list', 'children': [], 'value': '[]'},{'id': '48', 'type': 'for_statement', 'children': ['49', '52', '57']},{'id': '49', 'type': 'pattern_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'nb'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'conns'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ebunch'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'tuple', 'children': ['65', '66', '67']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'nb'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '68', 'type': 'if_statement', 'children': ['69', '75']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '74'], 'value': '>'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ebunch'},{'id': '74', 'type': 'integer', 'children': [], 'value': '0'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'add_edges_from'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ebunch'},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'G'}
def graph_from_connections(env, directed=False): G = DiGraph() if directed else Graph() conn_list = env.get_connections(data=True) for agent, conns in conn_list: G.add_node(agent) ebunch = [] for nb, data in conns.items(): ebunch.append((agent, nb, data)) if len(ebunch) > 0: G.add_edges_from(ebunch) return G
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'profile'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '7', 'type': 'integer', 'children': [], 'value': '200'},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'if_statement', 'children': ['10', '15', '149', '301']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': '=='},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '14', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '15', 'type': 'block', 'children': ['16', '132']},{'id': '16', 'type': 'if_statement', 'children': ['17', '26', '62']},{'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': 'request'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'GET'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': '"username"'},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'try_statement', 'children': ['28', '54']},{'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': 'user_profile'},{'id': '32', 'type': 'attribute', 'children': ['33', '53']},{'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': 'User'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '39', 'type': 'argument_list', 'children': ['40', '50']},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'username'},{'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': 'request'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'GET'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': '"username"'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'userprofile__public'},{'id': '52', 'type': 'True', 'children': []},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'userprofile'},{'id': '54', 'type': 'except_clause', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ObjectDoesNotExist'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'raise_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'Http404'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': '"user not found or have not public profile"'},{'id': '62', 'type': 'else_clause', 'children': ['63']},{'id': '63', 'type': 'block', 'children': ['64', '71', '122']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'get_user_id'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '71', 'type': 'if_statement', 'children': ['72', '86']},{'id': '72', 'type': 'boolean_operator', 'children': ['73', '81'], 'value': 'and'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'get_config'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77', '78']},{'id': '76', 'type': 'string', 'children': [], 'value': "'proso_user'"},{'id': '77', 'type': 'string', 'children': [], 'value': "'google.openid.migration'"},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '80', 'type': 'True', 'children': []},{'id': '81', 'type': 'not_operator', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'is_user_id_overridden'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '86', 'type': 'block', 'children': ['87', '96']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'migrated_user'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'migrate_google_openid_user'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '96', 'type': 'if_statement', 'children': ['97', '100']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'is'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'migrated_user'},{'id': '99', 'type': 'None', 'children': []},{'id': '100', 'type': 'block', 'children': ['101', '108', '114']},{'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': 'auth'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'logout'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'migrated_user'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'backend'},{'id': '113', 'type': 'string', 'children': [], 'value': "'social.backends.google.GoogleOAuth2'"},{'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': 'auth'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'migrated_user'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'user_profile'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'get_object_or_404'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'UserProfile'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '132', 'type': 'return_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137', '138', '141', '144']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'user_profile'},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '143', 'type': 'string', 'children': [], 'value': "'user_profile.html'"},{'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'help_text'},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '148', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '149', 'type': 'elif_clause', 'children': ['150', '155']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '154'], 'value': '=='},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '154', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '155', 'type': 'block', 'children': ['156', '287', '293']},{'id': '156', 'type': 'with_statement', 'children': ['157', '164']},{'id': '157', 'type': 'with_clause', 'children': ['158']},{'id': '158', 'type': 'with_item', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'atomic'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'block', 'children': ['165', '179', '186', '196', '206', '222', '238', '267', '281']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'to_save'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'json_body'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '177']},{'id': '172', 'type': 'attribute', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'get_user_id'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'user_profile'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'get_object_or_404'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'UserProfile'},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'to_save'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '205', 'type': 'None', 'children': []},{'id': '206', 'type': 'if_statement', 'children': ['207', '210']},{'id': '207', 'type': 'comparison_operator', 'children': ['208', '209'], 'value': 'in'},{'id': '208', 'type': 'string', 'children': [], 'value': "'send_emails'"},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'to_save'},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'user_profile'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'send_emails'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'to_save'},{'id': '221', 'type': 'string', 'children': [], 'value': "'send_emails'"},{'id': '222', 'type': 'if_statement', 'children': ['223', '226']},{'id': '223', 'type': 'comparison_operator', 'children': ['224', '225'], 'value': 'in'},{'id': '224', 'type': 'string', 'children': [], 'value': "'public'"},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'to_save'},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'user_profile'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'public'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'to_save'},{'id': '237', 'type': 'string', 'children': [], 'value': "'public'"},{'id': '238', 'type': 'if_statement', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '240', 'type': 'block', 'children': ['241', '252']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': '_save_user'},{'id': '246', 'type': 'argument_list', 'children': ['247', '248', '249']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'new'},{'id': '251', 'type': 'False', 'children': []},{'id': '252', 'type': 'if_statement', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'return_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260', '261', '264']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '263', 'type': 'string', 'children': [], 'value': "'user_json.html'"},{'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '266', 'type': 'integer', 'children': [], 'value': '400'},{'id': '267', 'type': 'if_statement', 'children': ['268', '271']},{'id': '268', 'type': 'comparison_operator', 'children': ['269', '270'], 'value': 'in'},{'id': '269', 'type': 'string', 'children': [], 'value': "'properties'"},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'to_save'},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'user_profile'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'save_properties'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'to_save'},{'id': '280', 'type': 'string', 'children': [], 'value': "'properties'"},{'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': 'user_profile'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '286', 'type': 'argument_list', 'children': []},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '292', 'type': 'string', 'children': [], 'value': '"GET"'},{'id': '293', 'type': 'return_statement', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '296', 'type': 'argument_list', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '298', 'type': 'keyword_argument', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '300', 'type': 'integer', 'children': [], 'value': '202'},{'id': '301', 'type': 'else_clause', 'children': ['302']},{'id': '302', 'type': 'block', 'children': ['303']},{'id': '303', 'type': 'return_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'HttpResponseBadRequest'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'string', 'children': [], 'value': '"method %s is not allowed"'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'method'}
def profile(request, status=200): if request.method == 'GET': if request.GET.get("username", False): try: user_profile = User.objects.get(username=request.GET.get("username"), userprofile__public=True).userprofile except ObjectDoesNotExist: raise Http404("user not found or have not public profile") else: user_id = get_user_id(request) if get_config('proso_user', 'google.openid.migration', default=True) and not is_user_id_overridden(request): migrated_user = migrate_google_openid_user(request.user) if migrated_user is not None: auth.logout(request) migrated_user.backend = 'social.backends.google.GoogleOAuth2' auth.login(request, migrated_user) user_profile = get_object_or_404(UserProfile, user_id=user_id) return render_json( request, user_profile, status=status, template='user_profile.html', help_text=profile.__doc__) elif request.method == 'POST': with transaction.atomic(): to_save = json_body(request.body.decode("utf-8")) user_id = get_user_id(request) user_profile = get_object_or_404(UserProfile, user_id=user_id) user = to_save.get('user', None) if 'send_emails' in to_save: user_profile.send_emails = bool(to_save['send_emails']) if 'public' in to_save: user_profile.public = bool(to_save['public']) if user: error = _save_user(request, user, new=False) if error: return render_json(request, error, template='user_json.html', status=400) if 'properties' in to_save: user_profile.save_properties(to_save['properties']) user_profile.save() request.method = "GET" return profile(request, status=202) else: return HttpResponseBadRequest("method %s is not allowed".format(request.method))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_session_identifiers'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'inputfile'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '16', '26', '175']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sessions'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'boolean_operator', 'children': ['18', '19'], 'value': 'and'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'inputfile'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'folder'},{'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': 'MQ2Exception'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'You should specify either a folder or a file'"},{'id': '26', 'type': 'if_statement', 'children': ['27', '28', '115']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '28', 'type': 'block', 'children': ['29', '42']},{'id': '29', 'type': 'if_statement', 'children': ['30', '39']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sessions'},{'id': '42', 'type': 'for_statement', 'children': ['43', '47', '53']},{'id': '43', 'type': 'pattern_list', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'walk'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'for_statement', 'children': ['55', '56', '57']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '57', 'type': 'block', 'children': ['58', '70']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '73']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'SUPPORTED_FILES'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'if_statement', 'children': ['75', '81']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '81', 'type': 'block', 'children': ['82', '91']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'wbook'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'xlrd'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'open_workbook'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '91', 'type': 'for_statement', 'children': ['92', '93', '98']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sheet'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'wbook'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sheets'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'if_statement', 'children': ['100', '105']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': 'not'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sheet'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sessions'},{'id': '105', 'type': 'block', 'children': ['106']},{'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': 'sessions'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'sheet'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '115', 'type': 'elif_clause', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'inputfile'},{'id': '117', 'type': 'block', 'children': ['118', '130']},{'id': '118', 'type': 'if_statement', 'children': ['119', '127']},{'id': '119', 'type': 'call', 'children': ['120', '125']},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'inputfile'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'sessions'},{'id': '130', 'type': 'for_statement', 'children': ['131', '132', '133']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'SUPPORTED_FILES'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'if_statement', 'children': ['135', '141']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'inputfile'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ext'},{'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': 'wbook'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'xlrd'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'open_workbook'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'inputfile'},{'id': '151', 'type': 'for_statement', 'children': ['152', '153', '158']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sheet'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'wbook'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'sheets'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'if_statement', 'children': ['160', '165']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '164'], 'value': 'not'},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sheet'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'sessions'},{'id': '165', 'type': 'block', 'children': ['166']},{'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': 'sessions'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'sheet'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '175', 'type': 'return_statement', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'sessions'}
def get_session_identifiers(cls, folder=None, inputfile=None): sessions = [] if inputfile and folder: raise MQ2Exception( 'You should specify either a folder or a file') if folder: if not os.path.isdir(folder): return sessions for root, dirs, files in os.walk(folder): for filename in files: filename = os.path.join(root, filename) for ext in SUPPORTED_FILES: if filename.endswith(ext): wbook = xlrd.open_workbook(filename) for sheet in wbook.sheets(): if sheet.name not in sessions: sessions.append(sheet.name) elif inputfile: if os.path.isdir(inputfile): return sessions for ext in SUPPORTED_FILES: if inputfile.endswith(ext): wbook = xlrd.open_workbook(inputfile) for sheet in wbook.sheets(): if sheet.name not in sessions: sessions.append(sheet.name) return sessions
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'template2regex'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ranges'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '45', '54', '58', '62', '79', '83', '87', '92', '96', '100', '104', '310', '322', '334', '344']},{'id': '9', 'type': 'if_statement', 'children': ['10', '30']},{'id': '10', 'type': 'boolean_operator', 'children': ['11', '15'], 'value': 'and'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '18', '24'], 'value': '<'},{'id': '16', 'type': 'unary_operator', 'children': ['17'], 'value': '-'},{'id': '17', 'type': 'integer', 'children': [], 'value': '1'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "'|'"},{'id': '24', 'type': 'binary_operator', 'children': ['25', '29'], 'value': '-'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'raise_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'InvalidTemplateError'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '%'},{'id': '36', 'type': 'string', 'children': [], 'value': '"\'|\' may only appear at the end, found at position %d in %s"'},{'id': '37', 'type': 'tuple', 'children': ['38', '44']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': "'|'"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '45', 'type': 'if_statement', 'children': ['46', '49']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ranges'},{'id': '48', 'type': 'None', 'children': []},{'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': 'ranges'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_RANGES'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'anchor'},{'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': 'state'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'S_PATH'},{'id': '62', 'type': 'if_statement', 'children': ['63', '74']},{'id': '63', 'type': 'boolean_operator', 'children': ['64', '68'], 'value': 'and'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '73'], 'value': '=='},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '71', 'type': 'unary_operator', 'children': ['72'], 'value': '-'},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'anchor'},{'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': 'params'},{'id': '82', 'type': 'list', 'children': [], 'value': '[]'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'bracketdepth'},{'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': 'result'},{'id': '90', 'type': 'list', 'children': ['91'], 'value': "['^']"},{'id': '91', 'type': 'string', 'children': [], 'value': "'^'"},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '95', 'type': 'string', 'children': [], 'value': '""'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '99', 'type': 'string', 'children': [], 'value': '"[^/]+"'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'rangename'},{'id': '103', 'type': 'None', 'children': []},{'id': '104', 'type': 'for_statement', 'children': ['105', '106', '112']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'template_splitter'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'if_statement', 'children': ['114', '117', '227']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '=='},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'S_PATH'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'if_statement', 'children': ['119', '125', '138', '154', '182', '195', '207', '213']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '124'], 'value': '>'},{'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': 'c'},{'id': '124', 'type': 'integer', 'children': [], 'value': '1'},{'id': '125', 'type': 'block', 'children': ['126']},{'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': 'result'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '138', 'type': 'elif_clause', 'children': ['139', '142']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '=='},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '141', 'type': 'string', 'children': [], 'value': "'['"},{'id': '142', 'type': 'block', 'children': ['143', '150']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'string', 'children': [], 'value': '"("'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'augmented_assignment', 'children': ['152', '153'], 'value': '+='},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'bracketdepth'},{'id': '153', 'type': 'integer', 'children': [], 'value': '1'},{'id': '154', 'type': 'elif_clause', 'children': ['155', '158']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': '=='},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '157', 'type': 'string', 'children': [], 'value': "']'"},{'id': '158', 'type': 'block', 'children': ['159', '163', '175']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'augmented_assignment', 'children': ['161', '162'], 'value': '-='},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'bracketdepth'},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'if_statement', 'children': ['164', '167']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': '<'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'bracketdepth'},{'id': '166', 'type': 'integer', 'children': [], 'value': '0'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'raise_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'InvalidTemplateError'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '%'},{'id': '173', 'type': 'string', 'children': [], 'value': '"Mismatched brackets in %s"'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'template'},{'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': 'result'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'string', 'children': [], 'value': '")?"'},{'id': '182', 'type': 'elif_clause', 'children': ['183', '186']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': '=='},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '185', 'type': 'string', 'children': [], 'value': "'{'"},{'id': '186', 'type': 'block', 'children': ['187', '191']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '190', 'type': 'string', 'children': [], 'value': '""'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'S_TEMPLATE'},{'id': '195', 'type': 'elif_clause', 'children': ['196', '199']},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': '=='},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '198', 'type': 'string', 'children': [], 'value': "'}'"},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'raise_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'InvalidTemplateError'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'binary_operator', 'children': ['205', '206'], 'value': '%'},{'id': '205', 'type': 'string', 'children': [], 'value': '"Mismatched braces in %s"'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '207', 'type': 'elif_clause', 'children': ['208', '211']},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '210'], 'value': '=='},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '210', 'type': 'string', 'children': [], 'value': "'|'"},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'pass_statement', 'children': []},{'id': '213', 'type': 'else_clause', 'children': ['214']},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '227', 'type': 'else_clause', 'children': ['228']},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'if_statement', 'children': ['230', '233', '282']},{'id': '230', 'type': 'comparison_operator', 'children': ['231', '232'], 'value': '=='},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '232', 'type': 'string', 'children': [], 'value': "'}'"},{'id': '233', 'type': 'block', 'children': ['234', '267', '274', '278']},{'id': '234', 'type': 'if_statement', 'children': ['235', '240', '254']},{'id': '235', 'type': 'boolean_operator', 'children': ['236', '237'], 'value': 'and'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'rangename'},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': 'in'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'rangename'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'ranges'},{'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': 'result'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '%'},{'id': '248', 'type': 'string', 'children': [], 'value': '"(?P<%s>%s)"'},{'id': '249', 'type': 'tuple', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '251', 'type': 'subscript', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'ranges'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'rangename'},{'id': '254', 'type': 'else_clause', 'children': ['255']},{'id': '255', 'type': 'block', 'children': ['256']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'binary_operator', 'children': ['263', '264'], 'value': '%'},{'id': '263', 'type': 'string', 'children': [], 'value': '"(?P<%s>%s)"'},{'id': '264', 'type': 'tuple', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'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': 'params'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'S_PATH'},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'rangename'},{'id': '281', 'type': 'None', 'children': []},{'id': '282', 'type': 'else_clause', 'children': ['283']},{'id': '283', 'type': 'block', 'children': ['284', '288']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '288', 'type': 'if_statement', 'children': ['289', '298']},{'id': '289', 'type': 'comparison_operator', 'children': ['290', '296'], 'value': '>'},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'string', 'children': [], 'value': '":"'},{'id': '296', 'type': 'unary_operator', 'children': ['297'], 'value': '-'},{'id': '297', 'type': 'integer', 'children': [], 'value': '1'},{'id': '298', 'type': 'block', 'children': ['299']},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '304']},{'id': '301', 'type': 'pattern_list', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'rangename'},{'id': '304', 'type': 'call', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'string', 'children': [], 'value': '":"'},{'id': '310', 'type': 'if_statement', 'children': ['311', '314']},{'id': '311', 'type': 'comparison_operator', 'children': ['312', '313'], 'value': '!='},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'bracketdepth'},{'id': '313', 'type': 'integer', 'children': [], 'value': '0'},{'id': '314', 'type': 'block', 'children': ['315']},{'id': '315', 'type': 'raise_statement', 'children': ['316']},{'id': '316', 'type': 'call', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'InvalidTemplateError'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'binary_operator', 'children': ['320', '321'], 'value': '%'},{'id': '320', 'type': 'string', 'children': [], 'value': '"Mismatched brackets in %s"'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '322', 'type': 'if_statement', 'children': ['323', '326']},{'id': '323', 'type': 'comparison_operator', 'children': ['324', '325'], 'value': '=='},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'S_TEMPLATE'},{'id': '326', 'type': 'block', 'children': ['327']},{'id': '327', 'type': 'raise_statement', 'children': ['328']},{'id': '328', 'type': 'call', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'InvalidTemplateError'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'binary_operator', 'children': ['332', '333'], 'value': '%'},{'id': '332', 'type': 'string', 'children': [], 'value': '"Mismatched braces in %s"'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '334', 'type': 'if_statement', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'anchor'},{'id': '336', 'type': 'block', 'children': ['337']},{'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': 'result'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '342', 'type': 'argument_list', 'children': ['343']},{'id': '343', 'type': 'string', 'children': [], 'value': "'$'"},{'id': '344', 'type': 'return_statement', 'children': ['345']},{'id': '345', 'type': 'expression_list', 'children': ['346', '352']},{'id': '346', 'type': 'call', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'string', 'children': [], 'value': '""'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '350', 'type': 'argument_list', 'children': ['351']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'params'}
def template2regex(template, ranges=None): if len(template) and -1 < template.find('|') < len(template) - 1: raise InvalidTemplateError("'|' may only appear at the end, found at position %d in %s" % (template.find('|'), template)) if ranges is None: ranges = DEFAULT_RANGES anchor = True state = S_PATH if len(template) and template[-1] == '|': anchor = False params = [] bracketdepth = 0 result = ['^'] name = "" pattern = "[^/]+" rangename = None for c in template_splitter.split(template): if state == S_PATH: if len(c) > 1: result.append(re.escape(c)) elif c == '[': result.append("(") bracketdepth += 1 elif c == ']': bracketdepth -= 1 if bracketdepth < 0: raise InvalidTemplateError("Mismatched brackets in %s" % template) result.append(")?") elif c == '{': name = "" state = S_TEMPLATE elif c == '}': raise InvalidTemplateError("Mismatched braces in %s" % template) elif c == '|': pass else: result.append(re.escape(c)) else: if c == '}': if rangename and rangename in ranges: result.append("(?P<%s>%s)" % (name, ranges[rangename])) else: result.append("(?P<%s>%s)" % (name, pattern)) params.append(name) state = S_PATH rangename = None else: name = c if name.find(":") > -1: name, rangename = name.split(":") if bracketdepth != 0: raise InvalidTemplateError("Mismatched brackets in %s" % template) if state == S_TEMPLATE: raise InvalidTemplateError("Mismatched braces in %s" % template) if anchor: result.append('$') return "".join(result), params
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'path'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'if_statement', 'children': ['10', '16', '93', '132']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '15'], 'value': 'in'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'if_statement', 'children': ['18', '21', '79']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'in'},{'id': '19', 'type': 'string', 'children': [], 'value': "':'"},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '21', 'type': 'block', 'children': ['22', '34', '42', '52', '62', '68']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "':'"},{'id': '33', 'type': 'integer', 'children': [], 'value': '1'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '37', 'type': 'subscript', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'named_routes'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'prefix_params'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '48', 'type': 'identifier', 'children': [], 'value': '_pop_params'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'prefix_path'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'list', 'children': [], 'value': '[]'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'prefix_params'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'next_mapper'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '+'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'prefix_path'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'next_mapper'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77', '78']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '79', 'type': 'else_clause', 'children': ['80']},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'return_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '90']},{'id': '83', 'type': 'attribute', 'children': ['84', '89']},{'id': '84', 'type': 'subscript', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'named_routes'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '93', 'type': 'elif_clause', 'children': ['94', '99']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'Route'},{'id': '99', 'type': 'block', 'children': ['100', '119']},{'id': '100', 'type': 'for_statement', 'children': ['101', '102', '105']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'routes'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'if_statement', 'children': ['107', '110']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'is'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '119', 'type': 'raise_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'InvalidArgumentError'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '%'},{'id': '124', 'type': 'string', 'children': [], 'value': '"Route \'%s\' not found in this %s object."'},{'id': '125', 'type': 'tuple', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'target'},{'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': '__class__'},{'id': '131', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '132', 'type': 'else_clause', 'children': ['133']},{'id': '133', 'type': 'block', 'children': ['134', '141', '160']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'target_id'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '141', 'type': 'if_statement', 'children': ['142', '147']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'in'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'target_id'},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': '_lookup'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'return_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '157']},{'id': '150', 'type': 'attribute', 'children': ['151', '156']},{'id': '151', 'type': 'subscript', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': '_lookup'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'target_id'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '160', 'type': 'raise_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'InvalidArgumentError'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '%'},{'id': '165', 'type': 'string', 'children': [], 'value': '"No Route found for target \'%s\' in this %s object."'},{'id': '166', 'type': 'tuple', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'target'},{'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': '__class__'},{'id': '172', 'type': 'identifier', 'children': [], 'value': '__name__'}
def path(self, target, args, kw): if type(target) in string_types: if ':' in target: prefix, rest = target.split(':', 1) route = self.named_routes[prefix] prefix_params = route._pop_params(args, kw) prefix_path = route.path([], prefix_params) next_mapper = route.resource return prefix_path + next_mapper.path(rest, args, kw) else: return self.named_routes[target].path(args, kw) elif isinstance(target, Route): for route in self.routes: if route is target: return route.path(args, kw) raise InvalidArgumentError("Route '%s' not found in this %s object." % (target, self.__class__.__name__)) else: target_id = id(target) if target_id in self._lookup: return self._lookup[target_id].path(args, kw) raise InvalidArgumentError("No Route found for target '%s' in this %s object." % (target, self.__class__.__name__))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_children_graph'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '26', '133']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'function_definition', 'children': ['27', '28', '30']},{'id': '27', 'type': 'function_name', 'children': [], 'value': '_children'},{'id': '28', 'type': 'parameters', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '30', 'type': 'block', 'children': ['31', '92']},{'id': '31', 'type': 'if_statement', 'children': ['32', '35', '54']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '39', 'type': 'call', 'children': ['40', '52']},{'id': '40', 'type': 'attribute', 'children': ['41', '51']},{'id': '41', 'type': 'call', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'Item'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '50', 'type': 'True', 'children': []},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'prefetch_related'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': "'children'"},{'id': '54', 'type': 'else_clause', 'children': ['55']},{'id': '55', 'type': 'block', 'children': ['56', '71']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '59', 'type': 'list_comprehension', 'children': ['60', '61', '68']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'iis'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'iis'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '74', 'type': 'call', 'children': ['75', '90']},{'id': '75', 'type': 'attribute', 'children': ['76', '89']},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'Item'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '82', 'type': 'argument_list', 'children': ['83', '86']},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'id__in'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '88', 'type': 'True', 'children': []},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'prefetch_related'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': "'children'"},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'dictionary_comprehension', 'children': ['94', '124', '127']},{'id': '94', 'type': 'pair', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'list_comprehension', 'children': ['102', '105', '114']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_item'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '105', 'type': 'for_in_clause', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_item'},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '113', 'type': 'argument_list', 'children': []},{'id': '114', 'type': 'if_clause', 'children': ['115']},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '119'], 'value': 'and'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': '_item'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '123'], 'value': 'not'},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_item'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '124', 'type': 'for_in_clause', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '127', 'type': 'if_clause', 'children': ['128']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '132'], 'value': 'not'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '133', 'type': 'if_statement', 'children': ['134', '137', '149']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': 'is'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '136', 'type': 'None', 'children': []},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_reachable_graph'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145', '146']},{'id': '144', 'type': 'None', 'children': []},{'id': '145', 'type': 'identifier', 'children': [], 'value': '_children'},{'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '149', 'type': 'else_clause', 'children': ['150']},{'id': '150', 'type': 'block', 'children': ['151', '164']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'graph'},{'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_children_graph'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160', '161']},{'id': '159', 'type': 'None', 'children': []},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': '_subset_graph'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '176'], 'value': '-'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'}
def get_children_graph(self, item_ids=None, language=None, forbidden_item_ids=None): if forbidden_item_ids is None: forbidden_item_ids = set() def _children(item_ids): if item_ids is None: items = Item.objects.filter(active=True).prefetch_related('children') else: item_ids = [ii for iis in item_ids.values() for ii in iis] items = Item.objects.filter(id__in=item_ids, active=True).prefetch_related('children') return { item.id: sorted([ _item.id for _item in item.children.all() if _item.active and _item.id not in forbidden_item_ids ]) for item in items if item.id not in forbidden_item_ids } if item_ids is None: return self._reachable_graph(None, _children, language=language) else: graph = self.get_children_graph(None, language, forbidden_item_ids=forbidden_item_ids) return self._subset_graph(graph, set(item_ids) - set(forbidden_item_ids))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_parents_graph'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '101', '112']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '14']},{'id': '11', 'type': 'function_name', 'children': [], 'value': '_parents'},{'id': '12', 'type': 'parameters', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '14', 'type': 'block', 'children': ['15', '76']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19', '38']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '23', 'type': 'call', 'children': ['24', '36']},{'id': '24', 'type': 'attribute', 'children': ['25', '35']},{'id': '25', 'type': 'call', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'Item'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '34', 'type': 'True', 'children': []},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'prefetch_related'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': "'parents'"},{'id': '38', 'type': 'else_clause', 'children': ['39']},{'id': '39', 'type': 'block', 'children': ['40', '55']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '43', 'type': 'list_comprehension', 'children': ['44', '45', '52']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'iis'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'for_in_clause', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'iis'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '58', 'type': 'call', 'children': ['59', '74']},{'id': '59', 'type': 'attribute', 'children': ['60', '73']},{'id': '60', 'type': 'call', 'children': ['61', '66']},{'id': '61', 'type': 'attribute', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'Item'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '66', 'type': 'argument_list', 'children': ['67', '70']},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'id__in'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '72', 'type': 'True', 'children': []},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'prefetch_related'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': "'parents'"},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'dictionary_comprehension', 'children': ['78', '98']},{'id': '78', 'type': 'pair', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'list_comprehension', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': '_item'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '89', 'type': 'for_in_clause', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': '_item'},{'id': '91', 'type': 'call', 'children': ['92', '97']},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'for_in_clause', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '101', 'type': 'return_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_reachable_graph'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108', '109']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_parents'},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '112', 'type': 'if_statement', 'children': ['113', '116', '128']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_reachable_graph'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124', '125']},{'id': '123', 'type': 'None', 'children': []},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_parents'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '128', 'type': 'else_clause', 'children': ['129']},{'id': '129', 'type': 'block', 'children': ['130', '140']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'get_parents_graph'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'None', 'children': []},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '140', 'type': 'return_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': '_subset_graph'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'item_ids'}
def get_parents_graph(self, item_ids, language=None): def _parents(item_ids): if item_ids is None: items = Item.objects.filter(active=True).prefetch_related('parents') else: item_ids = [ii for iis in item_ids.values() for ii in iis] items = Item.objects.filter(id__in=item_ids, active=True).prefetch_related('parents') return {item.id: sorted([_item.id for _item in item.parents.all()]) for item in items} return self._reachable_graph(item_ids, _parents, language=language) if item_ids is None: return self._reachable_graph(None, _parents, language=language) else: graph = self.get_parents_graph(None, language) return self._subset_graph(graph, item_ids)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_graph'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '114']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '14']},{'id': '11', 'type': 'function_name', 'children': [], 'value': '_related'},{'id': '12', 'type': 'parameters', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '14', 'type': 'block', 'children': ['15', '78']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19', '39']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '23', 'type': 'call', 'children': ['24', '36']},{'id': '24', 'type': 'attribute', 'children': ['25', '35']},{'id': '25', 'type': 'call', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'Item'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '34', 'type': 'True', 'children': []},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'prefetch_related'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'parents'"},{'id': '38', 'type': 'string', 'children': [], 'value': "'children'"},{'id': '39', 'type': 'else_clause', 'children': ['40']},{'id': '40', 'type': 'block', 'children': ['41', '56']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '44', 'type': 'list_comprehension', 'children': ['45', '46', '53']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'iis'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'for_in_clause', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'iis'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '59', 'type': 'call', 'children': ['60', '75']},{'id': '60', 'type': 'attribute', 'children': ['61', '74']},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'Item'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '67', 'type': 'argument_list', 'children': ['68', '71']},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'id__in'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '73', 'type': 'True', 'children': []},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'prefetch_related'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': "'parents'"},{'id': '77', 'type': 'string', 'children': [], 'value': "'children'"},{'id': '78', 'type': 'return_statement', 'children': ['79']},{'id': '79', 'type': 'dictionary_comprehension', 'children': ['80', '111']},{'id': '80', 'type': 'pair', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'list_comprehension', 'children': ['88', '91', '108']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_item'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '91', 'type': 'for_in_clause', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '93', 'type': 'list', 'children': ['94', '101'], 'value': '[item.parents.all(), item.children.all()]'},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '100', 'type': 'argument_list', 'children': []},{'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': 'item'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'for_in_clause', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_item'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'rel'},{'id': '111', 'type': 'for_in_clause', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '114', 'type': 'if_statement', 'children': ['115', '118', '130']},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'is'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '117', 'type': 'None', 'children': []},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'return_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': '_reachable_graph'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126', '127']},{'id': '125', 'type': 'None', 'children': []},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_related'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '130', 'type': 'else_clause', 'children': ['131']},{'id': '131', 'type': 'block', 'children': ['132', '142']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'graph'},{'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': 'get_graph'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'None', 'children': []},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': '_subset_graph'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'item_ids'}
def get_graph(self, item_ids, language=None): def _related(item_ids): if item_ids is None: items = Item.objects.filter(active=True).prefetch_related('parents', 'children') else: item_ids = [ii for iis in item_ids.values() for ii in iis] items = Item.objects.filter(id__in=item_ids, active=True).prefetch_related('parents', 'children') return {item.id: sorted([_item.id for rel in [item.parents.all(), item.children.all()] for _item in rel]) for item in items} if item_ids is None: return self._reachable_graph(None, _related, language=language) else: graph = self.get_graph(None, language) return self._subset_graph(graph, item_ids)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'translate_item_ids'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'is_nested'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '43', '53', '72', '76', '244']},{'id': '11', 'type': 'if_statement', 'children': ['12', '15', '23', '37']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'is_nested'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'function_definition', 'children': ['17', '18', '20']},{'id': '17', 'type': 'function_name', 'children': [], 'value': 'is_nested_fun'},{'id': '18', 'type': 'parameters', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'True', 'children': []},{'id': '23', 'type': 'elif_clause', 'children': ['24', '29']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'is_nested'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'function_definition', 'children': ['31', '32', '34']},{'id': '31', 'type': 'function_name', 'children': [], 'value': 'is_nested_fun'},{'id': '32', 'type': 'parameters', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'is_nested'},{'id': '37', 'type': 'else_clause', 'children': ['38']},{'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': 'is_nested_fun'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'is_nested'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'all_item_type_ids'},{'id': '46', 'type': 'call', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ItemType'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_all_item_type_ids'},{'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': 'groupped'},{'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': 'proso'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'group_by'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '66', 'type': 'lambda', 'children': ['67', '69']},{'id': '67', 'type': 'lambda_parameters', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'all_item_type_ids'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '75', 'type': 'dictionary', 'children': []},{'id': '76', 'type': 'for_statement', 'children': ['77', '80', '85']},{'id': '77', 'type': 'pattern_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'item_type_id'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'groupped'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'with_statement', 'children': ['87', '98']},{'id': '87', 'type': 'with_clause', 'children': ['88']},{'id': '88', 'type': 'with_item', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'timeit'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "'translating item type {}'"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'item_type_id'},{'id': '98', 'type': 'block', 'children': ['99', '111', '122', '136', '149', '208']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'item_type'},{'id': '102', 'type': 'subscript', 'children': ['103', '110']},{'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': 'ItemType'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'get_all_types'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'item_type_id'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '114', 'type': 'call', 'children': ['115', '120']},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ItemType'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'get_model'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'item_type_id'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '125', 'type': 'dictionary', 'children': ['126']},{'id': '126', 'type': 'pair', 'children': ['127', '135']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': "'{}__in'"},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'item_type'},{'id': '134', 'type': 'string', 'children': [], 'value': "'foreign_key'"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '136', 'type': 'if_statement', 'children': ['137', '140']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'in'},{'id': '138', 'type': 'string', 'children': [], 'value': "'language'"},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'item_type'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '148']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'item_type'},{'id': '147', 'type': 'string', 'children': [], 'value': "'language'"},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '149', 'type': 'if_statement', 'children': ['150', '170', '181', '200']},{'id': '150', 'type': 'boolean_operator', 'children': ['151', '163'], 'value': 'and'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'list_comprehension', 'children': ['155', '160']},{'id': '155', 'type': 'not_operator', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'is_nested_fun'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '160', 'type': 'for_in_clause', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '165', 'type': 'argument_list', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '169', 'type': 'string', 'children': [], 'value': "'prepare_related'"},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '174', 'type': 'call', 'children': ['175', '180']},{'id': '175', 'type': 'attribute', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'prepare_related'},{'id': '180', 'type': 'argument_list', 'children': []},{'id': '181', 'type': 'elif_clause', 'children': ['182', '189']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '184', 'type': 'argument_list', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '188', 'type': 'string', 'children': [], 'value': "'prepare'"},{'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': 'objs'},{'id': '193', 'type': 'call', 'children': ['194', '199']},{'id': '194', 'type': 'attribute', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'prepare'},{'id': '199', 'type': 'argument_list', 'children': []},{'id': '200', 'type': 'else_clause', 'children': ['201']},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '208', 'type': 'for_statement', 'children': ['209', '210', '217']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'dictionary_splat', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '217', 'type': 'block', 'children': ['218', '228']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '223', 'type': 'argument_list', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'item_type'},{'id': '227', 'type': 'string', 'children': [], 'value': "'foreign_key'"},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '233']},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'to_json'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'nested'},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'is_nested_fun'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '244', 'type': 'return_statement', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'result'}
def translate_item_ids(self, item_ids, language, is_nested=None): if is_nested is None: def is_nested_fun(x): return True elif isinstance(is_nested, bool): def is_nested_fun(x): return is_nested else: is_nested_fun = is_nested all_item_type_ids = ItemType.objects.get_all_item_type_ids() groupped = proso.list.group_by(item_ids, by=lambda item_id: all_item_type_ids[item_id]) result = {} for item_type_id, items in groupped.items(): with timeit('translating item type {}'.format(item_type_id)): item_type = ItemType.objects.get_all_types()[item_type_id] model = ItemType.objects.get_model(item_type_id) kwargs = {'{}__in'.format(item_type['foreign_key']): items} if 'language' in item_type: kwargs[item_type['language']] = language if any([not is_nested_fun(item_id) for item_id in items]) and hasattr(model.objects, 'prepare_related'): objs = model.objects.prepare_related() elif hasattr(model.objects, 'prepare'): objs = model.objects.prepare() else: objs = model.objects for obj in objs.filter(**kwargs): item_id = getattr(obj, item_type['foreign_key']) result[item_id] = obj.to_json(nested=is_nested_fun(item_id)) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_leaves'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '29', '44', '55', '71', '216']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '18', 'type': 'conditional_expression', 'children': ['19', '22', '25'], 'value': 'if'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'get_children_graph'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38', '41']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'get_children_counts'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'active'},{'id': '54', 'type': 'None', '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': 'item_ids'},{'id': '58', 'type': 'None', 'children': []},{'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': 'item_ids'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'function_definition', 'children': ['72', '73', '75']},{'id': '72', 'type': 'function_name', 'children': [], 'value': '_get_leaves'},{'id': '73', 'type': 'parameters', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '75', 'type': 'block', 'children': ['76', '82', '134', '174', '188', '198', '212']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'function_definition', 'children': ['83', '84', '86']},{'id': '83', 'type': 'function_name', 'children': [], 'value': '__search'},{'id': '84', 'type': 'parameters', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '86', 'type': 'block', 'children': ['87', '107', '123', '130']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'list_comprehension', 'children': ['97', '104']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '103', 'type': 'list', 'children': [], 'value': '[]'},{'id': '104', 'type': 'for_in_clause', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'item_ids'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'new_leaves'},{'id': '110', 'type': 'set_comprehension', 'children': ['111', '112', '115']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '115', 'type': 'if_clause', 'children': ['116']},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'not'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '122', 'type': 'argument_list', 'children': []},{'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': 'leaves'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'new_leaves'},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '-'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'new_leaves'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'fixed_point'},{'id': '137', 'type': 'argument_list', 'children': ['138', '149', '158', '167', '170']},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'is_zero'},{'id': '140', 'type': 'lambda', 'children': ['141', '143']},{'id': '141', 'type': 'lambda_parameters', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'to_visit'},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '148'], 'value': '=='},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'to_visit'},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'minus'},{'id': '151', 'type': 'lambda', 'children': ['152', '155']},{'id': '152', 'type': 'lambda_parameters', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'to_visit'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '-'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'to_visit'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'plus'},{'id': '160', 'type': 'lambda', 'children': ['161', '164']},{'id': '161', 'type': 'lambda_parameters', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'visited_x'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'visited_y'},{'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '|'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'visited_x'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'visited_y'},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '__search'},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '172', 'type': 'set', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '177', 'type': 'set_comprehension', 'children': ['178', '179', '182']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'leaf'},{'id': '179', 'type': 'for_in_clause', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'leaf'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '182', 'type': 'if_clause', 'children': ['183']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '187'], 'value': '=='},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'leaf'},{'id': '187', 'type': 'integer', 'children': [], 'value': '0'},{'id': '188', 'type': 'if_statement', 'children': ['189', '195']},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '194'], 'value': '>'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '194', 'type': 'integer', 'children': [], 'value': '0'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'return_statement', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '198', 'type': 'if_statement', 'children': ['199', '208']},{'id': '199', 'type': 'boolean_operator', 'children': ['200', '205'], 'value': 'and'},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '204'], 'value': '=='},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '204', 'type': 'integer', 'children': [], 'value': '0'},{'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': 'not'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'forbidden_item_ids'},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'return_statement', 'children': ['210']},{'id': '210', 'type': 'set', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '212', 'type': 'return_statement', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '215', 'type': 'argument_list', 'children': []},{'id': '216', 'type': 'return_statement', 'children': ['217']},{'id': '217', 'type': 'dictionary_comprehension', 'children': ['218', '224']},{'id': '218', 'type': 'pair', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': '_get_leaves'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '224', 'type': 'for_in_clause', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'item_ids'}
def get_leaves(self, item_ids=None, language=None, forbidden_item_ids=None): forbidden_item_ids = set() if forbidden_item_ids is None else set(forbidden_item_ids) children = self.get_children_graph(item_ids, language=language, forbidden_item_ids=forbidden_item_ids) counts = self.get_children_counts(active=None) if item_ids is None: item_ids = set(children.keys()) def _get_leaves(item_id): leaves = set() def __search(item_ids): result = set(flatten([children.get(item_id, []) for item_id in item_ids])) new_leaves = {item_id for item_id in result if item_id not in children.keys()} leaves.update(new_leaves) return result - new_leaves fixed_point( is_zero=lambda to_visit: len(to_visit) == 0, minus=lambda to_visit, visited: to_visit - visited, plus=lambda visited_x, visited_y: visited_x | visited_y, f=__search, x={item_id} ) leaves = {leaf for leaf in leaves if counts[leaf] == 0} if len(leaves) > 0: return leaves if counts[item_id] == 0 and item_id not in forbidden_item_ids: return {item_id} return set() return {item_id: _get_leaves(item_id) for item_id in item_ids}
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_image'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'imgtype'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'nsfw'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'hidden'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'filetype'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '33', '48', '63', '78', '104', '119', '153']},{'id': '21', 'type': 'if_statement', 'children': ['22', '27']},{'id': '22', 'type': 'boolean_operator', 'children': ['23', '25'], 'value': 'and'},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'imgtype'},{'id': '25', 'type': 'not_operator', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'tags'},{'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': 'MissingTypeOrTags'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': '"\'get_image\' requires at least one of either type or tags."'},{'id': '33', 'type': 'if_statement', 'children': ['34', '42']},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '36'], 'value': 'and'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'imgtype'},{'id': '36', 'type': 'not_operator', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'imgtype'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'raise_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': '"type of \'imgtype\' must be str."'},{'id': '48', 'type': 'if_statement', 'children': ['49', '57']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '51'], 'value': 'and'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '51', 'type': 'not_operator', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'raise_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': '"type of \'tags\' must be list or None."'},{'id': '63', 'type': 'if_statement', 'children': ['64', '72']},{'id': '64', 'type': 'boolean_operator', 'children': ['65', '66'], 'value': 'and'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'hidden'},{'id': '66', 'type': 'not_operator', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'hidden'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'raise_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': '"type of \'hidden\' must be bool or None."'},{'id': '78', 'type': 'if_statement', 'children': ['79', '98']},{'id': '79', 'type': 'boolean_operator', 'children': ['80', '88'], 'value': 'and'},{'id': '80', 'type': 'boolean_operator', 'children': ['81', '82'], 'value': 'and'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'nsfw'},{'id': '82', 'type': 'not_operator', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'nsfw'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '88', 'type': '()', 'children': ['89']},{'id': '89', 'type': 'boolean_operator', 'children': ['90', '95'], 'value': 'and'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'nsfw'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '=='},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'nsfw'},{'id': '97', 'type': 'string', 'children': [], 'value': "'only'"},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'raise_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'string', 'children': [], 'value': '"type of \'nsfw\' must be str, bool or None."'},{'id': '104', 'type': 'if_statement', 'children': ['105', '113']},{'id': '105', 'type': 'boolean_operator', 'children': ['106', '107'], 'value': 'and'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'filetype'},{'id': '107', 'type': 'not_operator', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'filetype'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'raise_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'string', 'children': [], 'value': '"type of \'filetype\' must be str."'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '148'], 'value': '+'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '143'], 'value': '+'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '138'], 'value': '+'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '133'], 'value': '+'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'},{'id': '127', 'type': 'string', 'children': [], 'value': "'https://api.weeb.sh/images/random'"},{'id': '128', 'type': '()', 'children': ['129']},{'id': '129', 'type': 'conditional_expression', 'children': ['130', '131', '132'], 'value': 'if'},{'id': '130', 'type': 'string', 'children': [], 'value': "f'?type={imgtype}'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'imgtype'},{'id': '132', 'type': 'string', 'children': [], 'value': "''"},{'id': '133', 'type': '()', 'children': ['134']},{'id': '134', 'type': 'conditional_expression', 'children': ['135', '136', '137'], 'value': 'if'},{'id': '135', 'type': 'string', 'children': [], 'value': 'f\'{"?" if not imgtype else "&"}tags={",".join(tags)}\''},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '137', 'type': 'string', 'children': [], 'value': "''"},{'id': '138', 'type': '()', 'children': ['139']},{'id': '139', 'type': 'conditional_expression', 'children': ['140', '141', '142'], 'value': 'if'},{'id': '140', 'type': 'string', 'children': [], 'value': "f'&nsfw={nsfw.lower()}'"},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'nsfw'},{'id': '142', 'type': 'string', 'children': [], 'value': "''"},{'id': '143', 'type': '()', 'children': ['144']},{'id': '144', 'type': 'conditional_expression', 'children': ['145', '146', '147'], 'value': 'if'},{'id': '145', 'type': 'string', 'children': [], 'value': "f'&hidden={hidden}'"},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'hidden'},{'id': '147', 'type': 'string', 'children': [], 'value': "''"},{'id': '148', 'type': '()', 'children': ['149']},{'id': '149', 'type': 'conditional_expression', 'children': ['150', '151', '152'], 'value': 'if'},{'id': '150', 'type': 'string', 'children': [], 'value': "f'&filetype={filetype}'"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'filetype'},{'id': '152', 'type': 'string', 'children': [], 'value': "''"},{'id': '153', 'type': 'with_statement', 'children': ['154', '164']},{'id': '154', 'type': 'with_clause', 'children': ['155']},{'id': '155', 'type': 'with_item', 'children': ['156']},{'id': '156', 'type': 'as_pattern', 'children': ['157', '162']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'aiohttp'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'ClientSession'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'as_pattern_target', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'with_statement', 'children': ['166', '182']},{'id': '166', 'type': 'with_clause', 'children': ['167']},{'id': '167', 'type': 'with_item', 'children': ['168']},{'id': '168', 'type': 'as_pattern', 'children': ['169', '180']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': '__headers'},{'id': '180', 'type': 'as_pattern_target', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'if_statement', 'children': ['184', '189', '210']},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '188'], 'value': '=='},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '188', 'type': 'integer', 'children': [], 'value': '200'},{'id': '189', 'type': 'block', 'children': ['190', '199']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'js'},{'id': '193', 'type': 'await', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '198', 'type': 'argument_list', 'children': []},{'id': '199', 'type': 'return_statement', 'children': ['200']},{'id': '200', 'type': 'list', 'children': ['201', '204', '207'], 'value': "[js['url'], js['id'], js['fileType']]"},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'js'},{'id': '203', 'type': 'string', 'children': [], 'value': "'url'"},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'js'},{'id': '206', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'js'},{'id': '209', 'type': 'string', 'children': [], 'value': "'fileType'"},{'id': '210', 'type': 'else_clause', 'children': ['211']},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'raise_statement', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'subscript', 'children': ['217', '224']},{'id': '217', 'type': '()', 'children': ['218']},{'id': '218', 'type': 'await', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '223', 'type': 'argument_list', 'children': []},{'id': '224', 'type': 'string', 'children': [], 'value': "'message'"}
async def get_image(self, imgtype=None, tags=None, nsfw=None, hidden=None, filetype=None): if not imgtype and not tags: raise MissingTypeOrTags("'get_image' requires at least one of either type or tags.") if imgtype and not isinstance(imgtype, str): raise TypeError("type of 'imgtype' must be str.") if tags and not isinstance(tags, list): raise TypeError("type of 'tags' must be list or None.") if hidden and not isinstance(hidden, bool): raise TypeError("type of 'hidden' must be bool or None.") if nsfw and not isinstance(nsfw, bool) and (isinstance(nsfw, str) and nsfw == 'only'): raise TypeError("type of 'nsfw' must be str, bool or None.") if filetype and not isinstance(filetype, str): raise TypeError("type of 'filetype' must be str.") url = 'https://api.weeb.sh/images/random' + (f'?type={imgtype}' if imgtype else '') + ( f'{"?" if not imgtype else "&"}tags={",".join(tags)}' if tags else '') + ( f'&nsfw={nsfw.lower()}' if nsfw else '') + (f'&hidden={hidden}' if hidden else '') + ( f'&filetype={filetype}' if filetype else '') async with aiohttp.ClientSession() as session: async with session.get(url, headers=self.__headers) as resp: if resp.status == 200: js = await resp.json() return [js['url'], js['id'], js['fileType']] else: raise Exception((await resp.json())['message'])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'query'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'logfile'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'jobID'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '17', '47', '70', '76', '82', '86', '114', '129', '142']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'logfile'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'readFromLogfile'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'if_statement', 'children': ['18', '29', '40']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '20'], 'value': 'and'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'jobID'},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '=='},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'jobID'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '33', 'type': 'list', 'children': ['34', '35', '36'], 'value': "['qstat', '-j', str(jobID)]"},{'id': '34', 'type': 'string', 'children': [], 'value': "'qstat'"},{'id': '35', 'type': 'string', 'children': [], 'value': "'-j'"},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'jobID'},{'id': '40', 'type': 'else_clause', 'children': ['41']},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '45', 'type': 'list', 'children': ['46'], 'value': "['qstat']"},{'id': '46', 'type': 'string', 'children': [], 'value': "'qstat'"},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'processoutput'},{'id': '50', 'type': 'call', 'children': ['51', '69']},{'id': '51', 'type': 'attribute', 'children': ['52', '68']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58', '63']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'communicate'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'processoutput'},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'processoutput'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'jobs'},{'id': '85', 'type': 'dictionary', 'children': []},{'id': '86', 'type': 'if_statement', 'children': ['87', '96']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '92'], 'value': '=='},{'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': 'jobID'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'if_statement', 'children': ['98', '107', '110']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '105'], 'value': '!='},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'serror'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': '"Following jobs do not exist"'},{'id': '105', 'type': 'unary_operator', 'children': ['106'], 'value': '-'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'return_statement', 'children': ['109']},{'id': '109', 'type': 'False', 'children': []},{'id': '110', 'type': 'else_clause', 'children': ['111']},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'return_statement', 'children': ['113']},{'id': '113', 'type': 'True', 'children': []},{'id': '114', 'type': 'if_statement', 'children': ['115', '121']},{'id': '115', 'type': 'not_operator', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '120', 'type': 'argument_list', 'children': []},{'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': 'colorprinter'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'string', 'children': [], 'value': '"No jobs running at present."'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '132', 'type': 'call', 'children': ['133', '140']},{'id': '133', 'type': 'attribute', 'children': ['134', '139']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '138', 'type': 'argument_list', 'children': []},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '142', 'type': 'if_statement', 'children': ['143', '149']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '148'], 'value': '>'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '148', 'type': 'integer', 'children': [], 'value': '2'},{'id': '149', 'type': 'block', 'children': ['150', '374']},{'id': '150', 'type': 'for_statement', 'children': ['151', '152', '157']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '154', 'type': 'slice', 'children': ['155', '156']},{'id': '155', 'type': 'integer', 'children': [], 'value': '2'},{'id': '156', 'type': 'colon', 'children': []},{'id': '157', 'type': 'block', 'children': ['158', '166', '175', '181', '217', '221', '275', '295', '308', '316']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '174', 'type': 'integer', 'children': [], 'value': '0'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'jobstate'},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '180', 'type': 'integer', 'children': [], 'value': '4'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '184', 'type': 'dictionary', 'children': ['185', '188', '193', '198', '203', '206']},{'id': '185', 'type': 'pair', 'children': ['186', '187']},{'id': '186', 'type': 'string', 'children': [], 'value': '"jobid"'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '188', 'type': 'pair', 'children': ['189', '190']},{'id': '189', 'type': 'string', 'children': [], 'value': '"prior"'},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'pair', 'children': ['194', '195']},{'id': '194', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '197', 'type': 'integer', 'children': [], 'value': '2'},{'id': '198', 'type': 'pair', 'children': ['199', '200']},{'id': '199', 'type': 'string', 'children': [], 'value': '"user"'},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '202', 'type': 'integer', 'children': [], 'value': '3'},{'id': '203', 'type': 'pair', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': '"state"'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'jobstate'},{'id': '206', 'type': 'pair', 'children': ['207', '208']},{'id': '207', 'type': 'string', 'children': [], 'value': '"submit/start at"'},{'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '%'},{'id': '209', 'type': 'string', 'children': [], 'value': '"%s %s"'},{'id': '210', 'type': 'tuple', 'children': ['211', '214']},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '213', 'type': 'integer', 'children': [], 'value': '5'},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '216', 'type': 'integer', 'children': [], 'value': '6'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'jataskID'},{'id': '220', 'type': 'integer', 'children': [], 'value': '0'},{'id': '221', 'type': 'if_statement', 'children': ['222', '225', '242']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': '=='},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'jobstate'},{'id': '224', 'type': 'string', 'children': [], 'value': '"r"'},{'id': '225', 'type': 'block', 'children': ['226', '234']},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '231']},{'id': '228', 'type': 'subscript', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '230', 'type': 'string', 'children': [], 'value': '"queue"'},{'id': '231', 'type': 'subscript', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '233', 'type': 'integer', 'children': [], 'value': '7'},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '239']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '238', 'type': 'string', 'children': [], 'value': '"slots"'},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '241', 'type': 'integer', 'children': [], 'value': '8'},{'id': '242', 'type': 'elif_clause', 'children': ['243', '246']},{'id': '243', 'type': 'comparison_operator', 'children': ['244', '245'], 'value': '=='},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'jobstate'},{'id': '245', 'type': 'string', 'children': [], 'value': '"qw"'},{'id': '246', 'type': 'block', 'children': ['247', '255']},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '252']},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '251', 'type': 'string', 'children': [], 'value': '"slots"'},{'id': '252', 'type': 'subscript', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '254', 'type': 'integer', 'children': [], 'value': '7'},{'id': '255', 'type': 'if_statement', 'children': ['256', '262']},{'id': '256', 'type': 'comparison_operator', 'children': ['257', '261'], 'value': '>='},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '261', 'type': 'integer', 'children': [], 'value': '9'},{'id': '262', 'type': 'block', 'children': ['263', '269']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'jataskID'},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '268', 'type': 'integer', 'children': [], 'value': '8'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '274']},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '273', 'type': 'string', 'children': [], 'value': '"ja-task-ID"'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'jataskID'},{'id': '275', 'type': 'if_statement', 'children': ['276', '282']},{'id': '276', 'type': 'comparison_operator', 'children': ['277', '281'], 'value': '>'},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '281', 'type': 'integer', 'children': [], 'value': '9'},{'id': '282', 'type': 'block', 'children': ['283', '289']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'jataskID'},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '288', 'type': 'integer', 'children': [], 'value': '9'},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '294']},{'id': '291', 'type': 'subscript', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '293', 'type': 'string', 'children': [], 'value': '"ja-task-ID"'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'jataskID'},{'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': 'jobs'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '300', 'type': 'boolean_operator', 'children': ['301', '307'], 'value': 'or'},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'jobs'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '307', 'type': 'dictionary', 'children': []},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'assignment', 'children': ['310', '315']},{'id': '310', 'type': 'subscript', 'children': ['311', '314']},{'id': '311', 'type': 'subscript', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'jobs'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'jataskID'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '316', 'type': 'if_statement', 'children': ['317', '323', '355']},{'id': '317', 'type': 'call', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '323', 'type': 'block', 'children': ['324', '332', '340']},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'jobdir'},{'id': '327', 'type': 'subscript', 'children': ['328', '331']},{'id': '328', 'type': 'subscript', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '331', 'type': 'string', 'children': [], 'value': '"Directory"'},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'assignment', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'jobtime'},{'id': '335', 'type': 'subscript', 'children': ['336', '339']},{'id': '336', 'type': 'subscript', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '339', 'type': 'string', 'children': [], 'value': '"TimeInSeconds"'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'colorprinter'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '345', 'type': 'argument_list', 'children': ['346']},{'id': '346', 'type': 'binary_operator', 'children': ['347', '348'], 'value': '%'},{'id': '347', 'type': 'string', 'children': [], 'value': '"Job %d submitted %d minutes ago. Status: \'%s\'. Destination directory: %s."'},{'id': '348', 'type': 'tuple', 'children': ['349', '350', '353', '354']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '350', 'type': 'binary_operator', 'children': ['351', '352'], 'value': '/'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'jobtime'},{'id': '352', 'type': 'integer', 'children': [], 'value': '60'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'jobstate'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'jobdir'},{'id': '355', 'type': 'else_clause', 'children': ['356']},{'id': '356', 'type': 'block', 'children': ['357']},{'id': '357', 'type': 'expression_statement', 'children': ['358']},{'id': '358', 'type': 'call', 'children': ['359', '362']},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'colorprinter'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '362', 'type': 'argument_list', 'children': ['363']},{'id': '363', 'type': 'binary_operator', 'children': ['364', '365'], 'value': '%'},{'id': '364', 'type': 'string', 'children': [], 'value': '"Job %d submitted at %s %s. Status: \'%s\'. Destination directory unknown."'},{'id': '365', 'type': 'tuple', 'children': ['366', '367', '370', '373']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '367', 'type': 'subscript', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '369', 'type': 'integer', 'children': [], 'value': '5'},{'id': '370', 'type': 'subscript', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '372', 'type': 'integer', 'children': [], 'value': '6'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'jobstate'},{'id': '374', 'type': 'return_statement', 'children': ['375']},{'id': '375', 'type': 'True', 'children': []}
def query(logfile, jobID = None): joblist = logfile.readFromLogfile() if jobID and type(jobID) == type(1): command = ['qstat', '-j', str(jobID)] else: command = ['qstat'] processoutput = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() output = processoutput[0] serror = processoutput[1] jobs = {} if type(jobID) == type(1): if serror.find("Following jobs do not exist") != -1: return False else: return True if not output.strip(): colorprinter.message("No jobs running at present.") output = output.strip().split("\n") if len(output) > 2: for line in output[2:]: tokens = line.split() jid = int(tokens[0]) jobstate = tokens[4] details = { "jobid" : jid, "prior" : tokens[1], "name" : tokens[2], "user" : tokens[3], "state" : jobstate, "submit/start at" : "%s %s" % (tokens[5], tokens[6]) } jataskID = 0 if jobstate == "r": details["queue"] = tokens[7] details["slots"] = tokens[8] elif jobstate == "qw": details["slots"] = tokens[7] if len(tokens) >= 9: jataskID = tokens[8] details["ja-task-ID"] = jataskID if len(tokens) > 9: jataskID = tokens[9] details["ja-task-ID"] = jataskID jobs[jid] = jobs.get(jid) or {} jobs[jid][jataskID] = details if joblist.get(jid): jobdir = joblist[jid]["Directory"] jobtime = joblist[jid]["TimeInSeconds"] colorprinter.message("Job %d submitted %d minutes ago. Status: '%s'. Destination directory: %s." % (jid, jobtime / 60, jobstate, jobdir)) else: colorprinter.message("Job %d submitted at %s %s. Status: '%s'. Destination directory unknown." % (jid, tokens[5], tokens[6], jobstate)) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'repository_tag'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'docker_file'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'use_cache'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '29', '59', '74', '82', '100', '105', '120', '124', '230', '235', '241']},{'id': '14', 'type': 'if_statement', 'children': ['15', '23']},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'docker'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Client'},{'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': 'TypeError'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': '"client needs to be of type docker.Client."'},{'id': '29', 'type': 'if_statement', 'children': ['30', '48']},{'id': '30', 'type': 'boolean_operator', 'children': ['31', '39'], 'value': 'or'},{'id': '31', 'type': 'not_operator', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'docker_file'},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '39', 'type': 'not_operator', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'docker_file'},{'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': 'Exception'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': '"docker file path doesn\'t exist: {0}"'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'docker_file'},{'id': '59', 'type': 'if_statement', 'children': ['60', '68']},{'id': '60', 'type': 'not_operator', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'repository_tag'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'raise_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': "'repository must be a string'"},{'id': '74', 'type': 'if_statement', 'children': ['75', '77']},{'id': '75', 'type': 'not_operator', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'tag'},{'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': 'tag'},{'id': '81', 'type': 'string', 'children': [], 'value': "'latest'"},{'id': '82', 'type': 'if_statement', 'children': ['83', '89']},{'id': '83', 'type': 'not_operator', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'use_cache'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'raise_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': '"use_cache must be a bool. {0} was passed."'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'use_cache'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'no_cache'},{'id': '103', 'type': 'not_operator', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'use_cache'},{'id': '105', 'type': 'if_statement', 'children': ['106', '109']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'not'},{'id': '107', 'type': 'string', 'children': [], 'value': "':'"},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'repository_tag'},{'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': 'repository_tag'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'string', 'children': [], 'value': '"{0}:{1}"'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'repository_tag'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'file_obj'},{'id': '123', 'type': 'None', 'children': []},{'id': '124', 'type': 'try_statement', 'children': ['125', '211', '219']},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'if_statement', 'children': ['127', '135', '186']},{'id': '127', 'type': 'call', 'children': ['128', '133']},{'id': '128', 'type': 'attribute', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'docker_file'},{'id': '135', 'type': 'block', 'children': ['136', '144', '160']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '143', 'type': 'argument_list', 'children': []},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'docker_file'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'string', 'children': [], 'value': '"./{0}"'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'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': 'os'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'relpath'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'docker_file'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '167', 'type': 'argument_list', 'children': ['168', '171', '174', '177', '180', '183']},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'nocache'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'no_cache'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'dockerfile'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'docker_file'},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'repository_tag'},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'rm'},{'id': '182', 'type': 'True', 'children': []},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '185', 'type': 'True', 'children': []},{'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', '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': 'client'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '195', 'type': 'argument_list', 'children': ['196', '199', '202', '205', '208']},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'docker_file'},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'repository_tag'},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'rm'},{'id': '204', 'type': 'True', 'children': []},{'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'nocache'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'no_cache'},{'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '210', 'type': 'True', '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']},{'id': '217', 'type': 'raise_statement', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '219', 'type': 'finally_clause', 'children': ['220']},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'if_statement', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'file_obj'},{'id': '223', 'type': 'block', 'children': ['224']},{'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': 'file_obj'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '229', 'type': 'argument_list', 'children': []},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'parse_stream'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'response'},{'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': 'client'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'return_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'Image'},{'id': '244', 'type': 'argument_list', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'repository_tag'}
def build(client, repository_tag, docker_file, tag=None, use_cache=False): if not isinstance(client, docker.Client): raise TypeError("client needs to be of type docker.Client.") if not isinstance(docker_file, six.string_types) or not os.path.exists(docker_file): raise Exception("docker file path doesn't exist: {0}".format(docker_file)) if not isinstance(repository_tag, six.string_types): raise TypeError('repository must be a string') if not tag: tag = 'latest' if not isinstance(use_cache, bool): raise TypeError("use_cache must be a bool. {0} was passed.".format(use_cache)) no_cache = not use_cache if ':' not in repository_tag: repository_tag = "{0}:{1}".format(repository_tag, tag) file_obj = None try: if os.path.isfile(docker_file): path = os.getcwd() docker_file = "./{0}".format(os.path.relpath(docker_file)) response = client.build( path=path, nocache=no_cache, dockerfile=docker_file, tag=repository_tag, rm=True, stream=True ) else: response = client.build(path=docker_file, tag=repository_tag, rm=True, nocache=no_cache, stream=True) except Exception as e: raise e finally: if file_obj: file_obj.close() parse_stream(response) client.close() return Image(client, repository_tag)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_class'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'block', 'children': ['6', '25']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '=='},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '11', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'render'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19', '20']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '18', 'type': 'string', 'children': [], 'value': "'classes_create.html'"},{'id': '19', 'type': 'dictionary', 'children': []},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'help_text'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'create_class'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '25', 'type': 'if_statement', 'children': ['26', '31', '213']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '30'], 'value': '=='},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '30', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '31', 'type': 'block', 'children': ['32', '72', '86', '129', '160', '178', '191', '197']},{'id': '32', 'type': 'if_statement', 'children': ['33', '50']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '42'], 'value': 'or'},{'id': '34', 'type': 'not_operator', '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': 'request'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'not_operator', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '45', 'type': 'argument_list', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '49', 'type': 'string', 'children': [], 'value': '"userprofile"'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56', '66', '69']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '56', 'type': 'dictionary', 'children': ['57', '63']},{'id': '57', 'type': 'pair', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': "'User is not logged in.'"},{'id': '63', 'type': 'pair', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': "'error_type'"},{'id': '65', 'type': 'string', 'children': [], 'value': "'user_unauthorized'"},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '68', 'type': 'string', 'children': [], 'value': "'classes_create.html'"},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '71', 'type': 'integer', 'children': [], 'value': '401'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'json_body'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '84']},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '86', 'type': 'if_statement', 'children': ['87', '107']},{'id': '87', 'type': 'boolean_operator', 'children': ['88', '91'], 'value': 'and'},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': 'in'},{'id': '89', 'type': 'string', 'children': [], 'value': "'code'"},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '91', 'type': 'call', 'children': ['92', '106']},{'id': '92', 'type': 'attribute', 'children': ['93', '105']},{'id': '93', 'type': 'call', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'Class'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '104', 'type': 'string', 'children': [], 'value': "'code'"},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'return_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113', '123', '126']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '113', 'type': 'dictionary', 'children': ['114', '120']},{'id': '114', 'type': 'pair', 'children': ['115', '116']},{'id': '115', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': "'A class with this code already exists.'"},{'id': '120', 'type': 'pair', 'children': ['121', '122']},{'id': '121', 'type': 'string', 'children': [], 'value': "'error_type'"},{'id': '122', 'type': 'string', 'children': [], 'value': "'class_with_code_exists'"},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '125', 'type': 'string', 'children': [], 'value': "'classes_create.html'"},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '128', 'type': 'integer', 'children': [], 'value': '400'},{'id': '129', 'type': 'if_statement', 'children': ['130', '138']},{'id': '130', 'type': 'boolean_operator', 'children': ['131', '134'], 'value': 'or'},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'not'},{'id': '132', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '134', 'type': 'not_operator', 'children': ['135']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '137', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144', '154', '157']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '144', 'type': 'dictionary', 'children': ['145', '151']},{'id': '145', 'type': 'pair', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'string', 'children': [], 'value': "'Class name is missing.'"},{'id': '151', 'type': 'pair', 'children': ['152', '153']},{'id': '152', 'type': 'string', 'children': [], 'value': "'error_type'"},{'id': '153', 'type': 'string', 'children': [], 'value': "'missing_class_name'"},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '156', 'type': 'string', 'children': [], 'value': "'classes_create.html'"},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '159', 'type': 'integer', 'children': [], 'value': '400'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'Class'},{'id': '165', 'type': 'argument_list', 'children': ['166', '171']},{'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '170', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'userprofile'},{'id': '178', 'type': 'if_statement', 'children': ['179', '182']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'in'},{'id': '180', 'type': 'string', 'children': [], 'value': "'code'"},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '190', 'type': 'string', 'children': [], 'value': "'code'"},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '196', 'type': 'argument_list', 'children': []},{'id': '197', 'type': 'return_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202', '207', '210']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'to_json'},{'id': '206', 'type': 'argument_list', 'children': []},{'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '209', 'type': 'string', 'children': [], 'value': "'classes_create.html'"},{'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '212', 'type': 'integer', 'children': [], 'value': '201'},{'id': '213', 'type': 'else_clause', 'children': ['214']},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'return_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'HttpResponseBadRequest'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'string', 'children': [], 'value': '"method %s is not allowed"'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'method'}
def create_class(request): if request.method == 'GET': return render(request, 'classes_create.html', {}, help_text=create_class.__doc__) if request.method == 'POST': if not request.user.is_authenticated() or not hasattr(request.user, "userprofile"): return render_json(request, { 'error': _('User is not logged in.'), 'error_type': 'user_unauthorized' }, template='classes_create.html', status=401) data = json_body(request.body.decode("utf-8")) if 'code' in data and Class.objects.filter(code=data['code']).exists(): return render_json(request, { 'error': _('A class with this code already exists.'), 'error_type': 'class_with_code_exists' }, template='classes_create.html', status=400) if 'name' not in data or not data['name']: return render_json(request, {'error': _('Class name is missing.'), 'error_type': 'missing_class_name'}, template='classes_create.html', status=400) cls = Class(name=data['name'], owner=request.user.userprofile) if 'code' in data: cls.code = data['code'] cls.save() return render_json(request, cls.to_json(), template='classes_create.html', status=201) else: return HttpResponseBadRequest("method %s is not allowed".format(request.method))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_student'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'block', 'children': ['6', '43', '62']},{'id': '6', 'type': 'if_statement', 'children': ['7', '16']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'get_config'},{'id': '10', 'type': 'argument_list', 'children': ['11', '12', '13']},{'id': '11', 'type': 'string', 'children': [], 'value': "'proso_user'"},{'id': '12', 'type': 'string', 'children': [], 'value': "'allow_create_students'"},{'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22', '32', '35', '40']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '22', 'type': 'dictionary', 'children': ['23', '29']},{'id': '23', 'type': 'pair', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'Creation of new users is not allowed.'"},{'id': '29', 'type': 'pair', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'error_type'"},{'id': '31', 'type': 'string', 'children': [], 'value': "'student_creation_not_allowed'"},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '34', 'type': 'string', 'children': [], 'value': "'class_create_student.html'"},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'help_text'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'create_student'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '42', 'type': 'integer', 'children': [], 'value': '403'},{'id': '43', 'type': 'if_statement', 'children': ['44', '49']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': '=='},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '48', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'render'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55', '56', '57']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '55', 'type': 'string', 'children': [], 'value': "'class_create_student.html'"},{'id': '56', 'type': 'dictionary', 'children': []},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'help_text'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'create_student'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '62', 'type': 'if_statement', 'children': ['63', '68', '409']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': '=='},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '67', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '68', 'type': 'block', 'children': ['69', '109', '123', '175', '206', '217', '233', '288', '354', '371', '377', '388']},{'id': '69', 'type': 'if_statement', 'children': ['70', '87']},{'id': '70', 'type': 'boolean_operator', 'children': ['71', '79'], 'value': 'or'},{'id': '71', 'type': 'not_operator', 'children': ['72']},{'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': 'request'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'not_operator', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '82', 'type': 'argument_list', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '86', 'type': 'string', 'children': [], 'value': '"userprofile"'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93', '103', '106']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '93', 'type': 'dictionary', 'children': ['94', '100']},{'id': '94', 'type': 'pair', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': "'User is not logged in.'"},{'id': '100', 'type': 'pair', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': "'error_type'"},{'id': '102', 'type': 'string', 'children': [], 'value': "'user_unauthorized'"},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '105', 'type': 'string', 'children': [], 'value': "'class_create_student.html'"},{'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '108', 'type': 'integer', 'children': [], 'value': '401'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'json_body'},{'id': '114', 'type': 'argument_list', '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': 'request'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '123', 'type': 'try_statement', 'children': ['124', '147']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'cls'},{'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': 'Class'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '134', 'type': 'argument_list', 'children': ['135', '140']},{'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '139', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '142', 'type': 'attribute', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'userprofile'},{'id': '147', 'type': 'except_clause', 'children': ['148', '153']},{'id': '148', 'type': 'tuple', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'Class'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'DoesNotExist'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'return_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159', '169', '172']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '159', 'type': 'dictionary', 'children': ['160', '166']},{'id': '160', 'type': 'pair', 'children': ['161', '162']},{'id': '161', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'string', 'children': [], 'value': "'Class with given id not found.'"},{'id': '166', 'type': 'pair', 'children': ['167', '168']},{'id': '167', 'type': 'string', 'children': [], 'value': "'error_type'"},{'id': '168', 'type': 'string', 'children': [], 'value': "'class_not_found'"},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '171', 'type': 'string', 'children': [], 'value': "'class_create_student.html'"},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '174', 'type': 'integer', 'children': [], 'value': '404'},{'id': '175', 'type': 'if_statement', 'children': ['176', '184']},{'id': '176', 'type': 'boolean_operator', 'children': ['177', '180'], 'value': 'or'},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'not'},{'id': '178', 'type': 'string', 'children': [], 'value': "'first_name'"},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '180', 'type': 'not_operator', 'children': ['181']},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '183', 'type': 'string', 'children': [], 'value': "'first_name'"},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'return_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190', '200', '203']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '190', 'type': 'dictionary', 'children': ['191', '197']},{'id': '191', 'type': 'pair', 'children': ['192', '193']},{'id': '192', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'string', 'children': [], 'value': "'First name code is missing.'"},{'id': '197', 'type': 'pair', 'children': ['198', '199']},{'id': '198', 'type': 'string', 'children': [], 'value': "'error_type'"},{'id': '199', 'type': 'string', 'children': [], 'value': "'missing_first_name'"},{'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '202', 'type': 'string', 'children': [], 'value': "'class_create_student.html'"},{'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '205', 'type': 'integer', 'children': [], 'value': '400'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'User'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'first_name'},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '216', 'type': 'string', 'children': [], 'value': "'first_name'"},{'id': '217', 'type': 'if_statement', 'children': ['218', '224']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'string', 'children': [], 'value': "'last_name'"},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'last_name'},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '232', 'type': 'string', 'children': [], 'value': "'last_name'"},{'id': '233', 'type': 'if_statement', 'children': ['234', '240']},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '240', 'type': 'block', 'children': ['241', '280']},{'id': '241', 'type': 'if_statement', 'children': ['242', '258']},{'id': '242', 'type': 'call', 'children': ['243', '257']},{'id': '243', 'type': 'attribute', 'children': ['244', '256']},{'id': '244', 'type': 'call', 'children': ['245', '250']},{'id': '245', 'type': 'attribute', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'User'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '253', 'type': 'subscript', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '255', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '257', 'type': 'argument_list', 'children': []},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'return_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '262', 'type': 'argument_list', 'children': ['263', '264', '274', '277']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '264', 'type': 'dictionary', 'children': ['265', '271']},{'id': '265', 'type': 'pair', 'children': ['266', '267']},{'id': '266', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'string', 'children': [], 'value': "'There is already a user with the given e-mail.'"},{'id': '271', 'type': 'pair', 'children': ['272', '273']},{'id': '272', 'type': 'string', 'children': [], 'value': "'error_type'"},{'id': '273', 'type': 'string', 'children': [], 'value': "'email_exists'"},{'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '276', 'type': 'string', 'children': [], 'value': "'class_create_student.html'"},{'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '279', 'type': 'integer', 'children': [], 'value': '400'},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'assignment', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '285', 'type': 'subscript', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '287', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '288', 'type': 'if_statement', 'children': ['289', '295', '343']},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '295', 'type': 'block', 'children': ['296', '335']},{'id': '296', 'type': 'if_statement', 'children': ['297', '313']},{'id': '297', 'type': 'call', 'children': ['298', '312']},{'id': '298', 'type': 'attribute', 'children': ['299', '311']},{'id': '299', 'type': 'call', 'children': ['300', '305']},{'id': '300', 'type': 'attribute', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'User'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '308', 'type': 'subscript', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '310', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '312', 'type': 'argument_list', 'children': []},{'id': '313', 'type': 'block', 'children': ['314']},{'id': '314', 'type': 'return_statement', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '317', 'type': 'argument_list', 'children': ['318', '319', '329', '332']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '319', 'type': 'dictionary', 'children': ['320', '326']},{'id': '320', 'type': 'pair', 'children': ['321', '322']},{'id': '321', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '322', 'type': 'call', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'string', 'children': [], 'value': "'There is already a user with the given username.'"},{'id': '326', 'type': 'pair', 'children': ['327', '328']},{'id': '327', 'type': 'string', 'children': [], 'value': "'error_type'"},{'id': '328', 'type': 'string', 'children': [], 'value': "'username_exists'"},{'id': '329', 'type': 'keyword_argument', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '331', 'type': 'string', 'children': [], 'value': "'class_create_student.html'"},{'id': '332', 'type': 'keyword_argument', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '334', 'type': 'integer', 'children': [], 'value': '400'},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'assignment', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '340', 'type': 'subscript', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '342', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '343', 'type': 'else_clause', 'children': ['344']},{'id': '344', 'type': 'block', 'children': ['345']},{'id': '345', 'type': 'expression_statement', 'children': ['346']},{'id': '346', 'type': 'assignment', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '350', 'type': 'call', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'get_unused_username'},{'id': '352', 'type': 'argument_list', 'children': ['353']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '354', 'type': 'if_statement', 'children': ['355', '361']},{'id': '355', 'type': 'call', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '359', 'type': 'argument_list', 'children': ['360']},{'id': '360', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '361', 'type': 'block', 'children': ['362']},{'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': 'user'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'set_password'},{'id': '367', 'type': 'argument_list', 'children': ['368']},{'id': '368', 'type': 'subscript', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '370', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '371', 'type': 'expression_statement', 'children': ['372']},{'id': '372', 'type': 'call', 'children': ['373', '376']},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '376', 'type': 'argument_list', 'children': []},{'id': '377', 'type': 'expression_statement', 'children': ['378']},{'id': '378', 'type': 'call', 'children': ['379', '384']},{'id': '379', 'type': 'attribute', 'children': ['380', '383']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'members'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '384', 'type': 'argument_list', 'children': ['385']},{'id': '385', 'type': 'attribute', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'userprofile'},{'id': '388', 'type': 'return_statement', 'children': ['389']},{'id': '389', 'type': 'call', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '391', 'type': 'argument_list', 'children': ['392', '393', '403', '406']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '393', 'type': 'call', 'children': ['394', '399']},{'id': '394', 'type': 'attribute', 'children': ['395', '398']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'userprofile'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'to_json'},{'id': '399', 'type': 'argument_list', 'children': ['400']},{'id': '400', 'type': 'keyword_argument', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'nested'},{'id': '402', 'type': 'True', 'children': []},{'id': '403', 'type': 'keyword_argument', 'children': ['404', '405']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '405', 'type': 'string', 'children': [], 'value': "'class_create_student.html'"},{'id': '406', 'type': 'keyword_argument', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '408', 'type': 'integer', 'children': [], 'value': '201'},{'id': '409', 'type': 'else_clause', 'children': ['410']},{'id': '410', 'type': 'block', 'children': ['411']},{'id': '411', 'type': 'return_statement', 'children': ['412']},{'id': '412', 'type': 'call', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'HttpResponseBadRequest'},{'id': '414', 'type': 'argument_list', 'children': ['415']},{'id': '415', 'type': 'call', 'children': ['416', '419']},{'id': '416', 'type': 'attribute', 'children': ['417', '418']},{'id': '417', 'type': 'string', 'children': [], 'value': '"method %s is not allowed"'},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '419', 'type': 'argument_list', 'children': ['420']},{'id': '420', 'type': 'attribute', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'method'}
def create_student(request): if not get_config('proso_user', 'allow_create_students', default=False): return render_json(request, { 'error': _('Creation of new users is not allowed.'), 'error_type': 'student_creation_not_allowed' }, template='class_create_student.html', help_text=create_student.__doc__, status=403) if request.method == 'GET': return render(request, 'class_create_student.html', {}, help_text=create_student.__doc__) if request.method == 'POST': if not request.user.is_authenticated() or not hasattr(request.user, "userprofile"): return render_json(request, { 'error': _('User is not logged in.'), 'error_type': 'user_unauthorized' }, template='class_create_student.html', status=401) data = json_body(request.body.decode("utf-8")) try: cls = Class.objects.get(pk=data['class'], owner=request.user.userprofile) except (Class.DoesNotExist, KeyError): return render_json(request, { 'error': _('Class with given id not found.'), 'error_type': 'class_not_found', }, template='class_create_student.html', status=404) if 'first_name' not in data or not data['first_name']: return render_json(request, { 'error': _('First name code is missing.'), 'error_type': 'missing_first_name' }, template='class_create_student.html', status=400) user = User(first_name=data['first_name']) if data.get('last_name'): user.last_name = data['last_name'] if data.get('email'): if User.objects.filter(email=data['email']).exists(): return render_json(request, { 'error': _('There is already a user with the given e-mail.'), 'error_type': 'email_exists' }, template='class_create_student.html', status=400) user.email = data['email'] if data.get('username'): if User.objects.filter(username=data['username']).exists(): return render_json(request, { 'error': _('There is already a user with the given username.'), 'error_type': 'username_exists' }, template='class_create_student.html', status=400) user.username = data['username'] else: user.username = get_unused_username(user) if data.get('password'): user.set_password(data['password']) user.save() cls.members.add(user.userprofile) return render_json(request, user.userprofile.to_json(nested=True), template='class_create_student.html', status=201) else: return HttpResponseBadRequest("method %s is not allowed".format(request.method))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '80']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lograptor'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41', '44', '47', '50', '53', '56', '59', '62', '65', '68', '71', '74', '77']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '10', 'type': 'string', 'children': [], 'value': "'ruled'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'cfgfiles'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'apps'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'hosts'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'time_period'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'time_range'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'case'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'invert'},{'id': '34', 'type': 'False', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '37', 'type': 'False', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'files_with_match'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'default_parameter', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '43', 'type': 'False', 'children': []},{'id': '44', 'type': 'default_parameter', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '46', 'type': 'False', 'children': []},{'id': '47', 'type': 'default_parameter', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'max_count'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'default_parameter', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'only_matching'},{'id': '52', 'type': 'False', 'children': []},{'id': '53', 'type': 'default_parameter', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'line_number'},{'id': '55', 'type': 'False', 'children': []},{'id': '56', 'type': 'default_parameter', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'with_filename'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'default_parameter', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ip_lookup'},{'id': '61', 'type': 'False', 'children': []},{'id': '62', 'type': 'default_parameter', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'uid_lookup'},{'id': '64', 'type': 'False', 'children': []},{'id': '65', 'type': 'default_parameter', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'anonymize'},{'id': '67', 'type': 'False', 'children': []},{'id': '68', 'type': 'default_parameter', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '70', 'type': 'False', 'children': []},{'id': '71', 'type': 'default_parameter', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'before_context'},{'id': '73', 'type': 'integer', 'children': [], 'value': '0'},{'id': '74', 'type': 'default_parameter', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'after_context'},{'id': '76', 'type': 'integer', 'children': [], 'value': '0'},{'id': '77', 'type': 'default_parameter', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'block', 'children': ['81', '87', '95', '101', '107', '113', '119', '125', '131', '137', '143', '149', '155', '161', '167', '173', '179', '185', '191', '197', '203', '209', '215', '221', '227', '239', '250', '261', '272', '279']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'cli_parser'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'create_argument_parser'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'cli_parser'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'cfgfiles'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'cfgfiles'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'time_period'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'time_period'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'time_range'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'time_range'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'case'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'case'},{'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': 'args'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'invert'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'invert'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'files_with_match'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'files_with_match'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'max_count'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'max_count'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'only_matching'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'only_matching'},{'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': 'args'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'line_number'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'line_number'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'with_filename'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'with_filename'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'anonymize'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'anonymize'},{'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': 'args'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'ip_lookup'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'ip_lookup'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'uid_lookup'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'uid_lookup'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'thread'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'after_context'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'after_context'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'before_context'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'before_context'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '232', 'type': 'conditional_expression', 'children': ['233', '235', '238'], 'value': 'if'},{'id': '233', 'type': 'list', 'children': ['234'], 'value': "['']"},{'id': '234', 'type': 'string', 'children': [], 'value': "''"},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '237'], 'value': 'is'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '237', 'type': 'None', 'children': []},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '239', 'type': 'if_statement', 'children': ['240', '243']},{'id': '240', 'type': 'comparison_operator', 'children': ['241', '242'], 'value': 'is'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'apps'},{'id': '242', 'type': 'None', 'children': []},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'apps'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'apps'},{'id': '250', 'type': 'if_statement', 'children': ['251', '254']},{'id': '251', 'type': 'comparison_operator', 'children': ['252', '253'], 'value': 'is'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'hosts'},{'id': '253', 'type': 'None', 'children': []},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'hosts'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'hosts'},{'id': '261', 'type': 'if_statement', 'children': ['262', '265']},{'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': 'is'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '264', 'type': 'None', 'children': []},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': '_lograptor'},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'LogRaptor'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '279', 'type': 'return_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': '_lograptor'},{'id': '282', 'type': 'argument_list', 'children': []}
def lograptor(files, patterns=None, matcher='ruled', cfgfiles=None, apps=None, hosts=None, filters=None, time_period=None, time_range=None, case=False, invert=False, word=False, files_with_match=None, count=False, quiet=False, max_count=0, only_matching=False, line_number=False, with_filename=None, ip_lookup=False, uid_lookup=False, anonymize=False, thread=False, before_context=0, after_context=0, context=0): cli_parser = create_argument_parser() args = cli_parser.parse_args() args.files = files args.matcher = matcher args.cfgfiles = cfgfiles args.time_period = time_period args.time_range = time_range args.case = case args.invert = invert args.word = word args.files_with_match = files_with_match args.count = count args.quiet = quiet args.max_count = max_count args.only_matching = only_matching args.line_number = line_number args.with_filename = with_filename args.anonymize = anonymize args.ip_lookup = ip_lookup args.uid_lookup = uid_lookup args.thread = thread args.context = context args.after_context = after_context args.before_context = before_context args.patterns = [''] if patterns is None else patterns if apps is not None: args.apps = apps if hosts is not None: args.hosts = hosts if filters is not None: args.filters = filters _lograptor = LogRaptor(args) return _lograptor()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sanitize_codon_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'codon_list'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'forbidden_seqs'},{'id': '7', 'type': 'tuple', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '31', '37', '53', '68', '89', '102', '106', '122']},{'id': '9', 'type': 'for_statement', 'children': ['10', '11', '12']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'codon'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'codon_list'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'if_statement', 'children': ['14', '20']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '19'], 'value': '!='},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'codon'},{'id': '19', 'type': 'integer', 'children': [], 'value': '3'},{'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': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': '"Codons must have exactly 3 bases: \'{}\'"'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'codon'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'bad_seqs'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '36', 'type': 'argument_list', 'children': []},{'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': 'bad_seqs'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '42', 'type': 'generator_expression', 'children': ['43', '50']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'restriction_sites'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'forbidden_seqs'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'bad_seqs'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '58', 'type': 'generator_expression', 'children': ['59', '65']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'dna'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'reverse_complement'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'bad_seqs'},{'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': 'bad_seqs'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '73', 'type': 'generator_expression', 'children': ['74', '84']},{'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '*'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '76', 'type': '()', 'children': ['77']},{'id': '77', 'type': 'binary_operator', 'children': ['78', '83'], 'value': '+'},{'id': '78', 'type': 'subscript', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'gen9'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'homopolymer_max_lengths'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'dna'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dna_bases'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'bad_seqs'},{'id': '92', 'type': 'list_comprehension', 'children': ['93', '99']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'dna'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'dna_to_re'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'bs'},{'id': '99', 'type': 'for_in_clause', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'bs'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'bad_seqs'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'num_corrections'},{'id': '105', 'type': 'integer', 'children': [], 'value': '0'},{'id': '106', 'type': 'for_statement', 'children': ['107', '108', '109']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'bad_seq'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'bad_seqs'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'while_statement', 'children': ['111', '117']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'remove_bad_sequence'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115', '116']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'codon_list'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'bad_seq'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'bad_seqs'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'augmented_assignment', 'children': ['120', '121'], 'value': '+='},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'num_corrections'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'return_statement', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'num_corrections'}
def sanitize_codon_list(codon_list, forbidden_seqs=()): for codon in codon_list: if len(codon) != 3: raise ValueError("Codons must have exactly 3 bases: '{}'".format(codon)) bad_seqs = set() bad_seqs.union( restriction_sites.get(seq, seq) for seq in forbidden_seqs) bad_seqs.union( dna.reverse_complement(seq) for seq in bad_seqs) bad_seqs.union( base * (gen9.homopolymer_max_lengths[base] + 1) for base in dna.dna_bases) bad_seqs = [ dna.dna_to_re(bs) for bs in bad_seqs] num_corrections = 0 for bad_seq in bad_seqs: while remove_bad_sequence(codon_list, bad_seq, bad_seqs): num_corrections += 1 return num_corrections
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_node'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '6', 'type': 'block', 'children': ['7', '15']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'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': 'nodes'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'if_statement', 'children': ['16', '24', '57']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '21'], 'value': '<='},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'm0'},{'id': '24', 'type': 'block', 'children': ['25', '41']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'other_nodes'},{'id': '28', 'type': 'list_comprehension', 'children': ['29', '30', '33']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '33', 'type': 'if_clause', 'children': ['34']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': '!='},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '41', 'type': 'for_statement', 'children': ['42', '43', '44']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'other_nodes'},{'id': '44', 'type': 'block', 'children': ['45']},{'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': 'node'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '50', 'type': 'argument_list', 'children': ['51', '54']},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '53', 'type': 'string', 'children': [], 'value': '"both"'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'whom'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '57', 'type': 'else_clause', 'children': ['58']},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'for_statement', 'children': ['60', '61', '67']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'idx_newvector'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'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': 'm'},{'id': '67', 'type': 'block', 'children': ['68', '98', '116', '133', '146', '150', '174']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'these_nodes'},{'id': '71', 'type': 'list_comprehension', 'children': ['72', '73', '76']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '73', 'type': 'for_in_clause', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '76', 'type': 'if_clause', 'children': ['77']},{'id': '77', 'type': '()', 'children': ['78']},{'id': '78', 'type': 'boolean_operator', 'children': ['79', '86'], 'value': 'and'},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '83'], 'value': '!='},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '86', 'type': 'not_operator', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'is_connected'},{'id': '91', 'type': 'argument_list', 'children': ['92', '95']},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '94', 'type': 'string', 'children': [], 'value': '"either"'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'whom'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'outdegrees'},{'id': '101', 'type': 'list_comprehension', 'children': ['102', '113']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'vectors'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '112', 'type': 'string', 'children': [], 'value': '"outgoing"'},{'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'these_nodes'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '119', 'type': 'list_comprehension', 'children': ['120', '130']},{'id': '120', 'type': '()', 'children': ['121']},{'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '/'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '123', 'type': '()', 'children': ['124']},{'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '*'},{'id': '125', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'outdegrees'},{'id': '130', 'type': 'for_in_clause', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'outdegrees'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'rnd'},{'id': '136', 'type': 'binary_operator', 'children': ['137', '142'], 'value': '*'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'cur'},{'id': '149', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '150', 'type': 'for_statement', 'children': ['151', '154', '158']},{'id': '151', 'type': 'pattern_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '158', 'type': 'block', 'children': ['159', '163']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'augmented_assignment', 'children': ['161', '162'], 'value': '+='},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'cur'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '163', 'type': 'if_statement', 'children': ['164', '167']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': '<'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'rnd'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'cur'},{'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': 'vector_to'},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'these_nodes'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '179', 'type': 'argument_list', 'children': ['180', '183']},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '182', 'type': 'string', 'children': [], 'value': '"both"'},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'whom'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'vector_to'}
def add_node(self, node): nodes = self.nodes() if len(nodes) <= self.m0: other_nodes = [n for n in nodes if n.id != node.id] for n in other_nodes: node.connect(direction="both", whom=n) else: for idx_newvector in xrange(self.m): these_nodes = [ n for n in nodes if ( n.id != node.id and not n.is_connected(direction="either", whom=node))] outdegrees = [ len(n.vectors(direction="outgoing")) for n in these_nodes] ps = [(d / (1.0 * sum(outdegrees))) for d in outdegrees] rnd = random.random() * sum(ps) cur = 0.0 for i, p in enumerate(ps): cur += p if rnd < cur: vector_to = these_nodes[i] node.connect(direction="both", whom=vector_to)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_concepts_to_recalculate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '15', '32', '41', '49', '65', '81', '97', '107', '248', '257']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'only_one_user'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'if_statement', 'children': ['16', '22']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '22', 'type': 'block', 'children': ['23', '27']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'only_one_user'},{'id': '26', 'type': 'True', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '30', 'type': 'list', 'children': ['31'], 'value': '[users]'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_item_concept_mapping'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'current_user_stats'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'lambda', 'children': ['48']},{'id': '48', 'type': 'dictionary', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'user_stats_qs'},{'id': '52', 'type': 'call', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'UserStat'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '58', 'type': 'argument_list', 'children': ['59', '62']},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'user__in'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '64', 'type': 'string', 'children': [], 'value': '"answer_count"'},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'is'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '68', 'type': 'None', 'children': []},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'user_stats_qs'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'user_stats_qs'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'concept__in'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '81', 'type': 'for_statement', 'children': ['82', '83', '84']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'user_stat'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'user_stats_qs'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '96']},{'id': '87', 'type': 'subscript', 'children': ['88', '93']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'current_user_stats'},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'user_stat'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'user_stat'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'concept_id'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'user_stat'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'concepts_to_recalculate'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'lambda', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'for_statement', 'children': ['108', '112', '137']},{'id': '108', 'type': 'pattern_list', 'children': ['109', '110', '111']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '112', 'type': 'call', 'children': ['113', '132']},{'id': '113', 'type': 'attribute', 'children': ['114', '131']},{'id': '114', 'type': 'call', 'children': ['115', '128']},{'id': '115', 'type': 'attribute', 'children': ['116', '126', '127']},{'id': '116', 'type': 'call', 'children': ['117', '122']},{'id': '117', 'type': 'attribute', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'Answer'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'user__in'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '126', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'values_list'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': '"user_id"'},{'id': '130', 'type': 'string', 'children': [], 'value': '"item"'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'annotate'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Max'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'string', 'children': [], 'value': '"time"'},{'id': '137', 'type': 'block', 'children': ['138', '144', '155', '166']},{'id': '138', 'type': 'if_statement', 'children': ['139', '142']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': 'not'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'continue_statement', 'children': []},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'time_expiration_lower_bound'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'get_config'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151', '152']},{'id': '150', 'type': 'string', 'children': [], 'value': "'proso_models'"},{'id': '151', 'type': 'string', 'children': [], 'value': "'knowledge_overview.time_shift_hours'"},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '154', 'type': 'integer', 'children': [], 'value': '4'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'time_expiration_factor'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'get_config'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162', '163']},{'id': '161', 'type': 'string', 'children': [], 'value': "'proso_models'"},{'id': '162', 'type': 'string', 'children': [], 'value': "'knowledge_overview.time_expiration_factor'"},{'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '165', 'type': 'integer', 'children': [], 'value': '2'},{'id': '166', 'type': 'for_statement', 'children': ['167', '168', '171']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '171', 'type': 'block', 'children': ['172', '213']},{'id': '172', 'type': 'if_statement', 'children': ['173', '193']},{'id': '173', 'type': 'boolean_operator', 'children': ['174', '183', '184'], 'value': 'and'},{'id': '174', 'type': 'boolean_operator', 'children': ['175', '178'], 'value': 'and'},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': 'in'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'current_user_stats'},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': 'in'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'current_user_stats'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '183', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '192'], 'value': '>'},{'id': '185', 'type': 'attribute', 'children': ['186', '191']},{'id': '186', 'type': 'subscript', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'current_user_stats'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'if_statement', 'children': ['195', '211']},{'id': '195', 'type': 'not_operator', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'has_time_expired'},{'id': '200', 'type': 'argument_list', 'children': ['201', '208', '209', '210']},{'id': '201', 'type': 'attribute', 'children': ['202', '207']},{'id': '202', 'type': 'subscript', 'children': ['203', '206']},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'current_user_stats'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'time_expiration_lower_bound'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'time_expiration_factor'},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'continue_statement', 'children': []},{'id': '213', 'type': 'if_statement', 'children': ['214', '238']},{'id': '214', 'type': 'boolean_operator', 'children': ['215', '218'], 'value': 'or'},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': 'is'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '217', 'type': 'None', 'children': []},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'in'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '220', 'type': '()', 'children': ['221']},{'id': '221', 'type': 'conditional_expression', 'children': ['222', '229', '237'], 'value': 'if'},{'id': '222', 'type': 'list_comprehension', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '226', 'type': 'for_in_clause', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '236'], 'value': '=='},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'subscript', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '235', 'type': 'integer', 'children': [], 'value': '0'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'Concept'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'Concept'},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '246']},{'id': '241', 'type': 'attribute', 'children': ['242', '245']},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'concepts_to_recalculate'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '248', 'type': 'if_statement', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'only_one_user'},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'return_statement', 'children': ['252']},{'id': '252', 'type': 'subscript', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'concepts_to_recalculate'},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '256', 'type': 'integer', 'children': [], 'value': '0'},{'id': '257', 'type': 'return_statement', 'children': ['258']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'concepts_to_recalculate'}
def get_concepts_to_recalculate(self, users, lang, concepts=None): only_one_user = False if not isinstance(users, list): only_one_user = True users = [users] mapping = self.get_item_concept_mapping(lang) current_user_stats = defaultdict(lambda: {}) user_stats_qs = UserStat.objects.filter(user__in=users, stat="answer_count") if concepts is not None: user_stats_qs = user_stats_qs.filter(concept__in=concepts) for user_stat in user_stats_qs: current_user_stats[user_stat.user_id][user_stat.concept_id] = user_stat concepts_to_recalculate = defaultdict(lambda: set()) for user, item, time in Answer.objects.filter(user__in=users)\ .values_list("user_id", "item").annotate(Max("time")): if item not in mapping: continue time_expiration_lower_bound = get_config('proso_models', 'knowledge_overview.time_shift_hours', default=4) time_expiration_factor = get_config('proso_models', 'knowledge_overview.time_expiration_factor', default=2) for concept in mapping[item]: if user in current_user_stats and concept in current_user_stats[user] \ and current_user_stats[user][concept].time > time: if not self.has_time_expired(current_user_stats[user][concept].time, time, time_expiration_lower_bound, time_expiration_factor): continue if concepts is None or concept in ([c.pk for c in concepts] if type(concepts[0]) == Concept else Concept): concepts_to_recalculate[user].add(concept) if only_one_user: return concepts_to_recalculate[users[0]] return concepts_to_recalculate
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'recalculate_concepts'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '19', '71', '77', '83']},{'id': '10', 'type': 'if_statement', 'children': ['11', '17']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '16'], 'value': '=='},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '16', 'type': 'integer', 'children': [], 'value': '0'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': []},{'id': '19', 'type': 'if_statement', 'children': ['20', '23', '56']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '27', 'type': 'call', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'Concept'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_concept_item_mapping'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '36', 'type': 'call', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'Concept'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'pk__in'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '55', 'type': 'argument_list', 'children': []},{'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': 'items'},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'Concept'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'get_concept_item_mapping'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'get_environment'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'mastery_threshold'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'get_mastery_trashold'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'for_statement', 'children': ['84', '87', '92']},{'id': '84', 'type': 'pattern_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'block', 'children': ['93', '112', '122', '132', '160', '164', '170', '385', '396']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'all_items'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'list_comprehension', 'children': ['106', '109']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '109', 'type': 'for_in_clause', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'answer_counts'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'number_of_answers_more_items'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'all_items'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'correct_answer_counts'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'number_of_correct_answers_more_items'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'all_items'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'predictions'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'all_items'},{'id': '145', 'type': 'call', 'children': ['146', '151']},{'id': '146', 'type': 'attribute', 'children': ['147', '150']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'get_predictive_model'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'predict_more_items'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153', '154', '155']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'all_items'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'get_time_for_knowledge_overview'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'new_user_stats'},{'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': 'stats_to_delete_condition'},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'for_statement', 'children': ['171', '172', '173']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '173', 'type': 'block', 'children': ['174', '221', '342', '354']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'answer_aggregates'},{'id': '177', 'type': 'call', 'children': ['178', '195']},{'id': '178', 'type': 'attribute', 'children': ['179', '194']},{'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': 'Answer'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '185', 'type': 'argument_list', 'children': ['186', '189']},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'item__in'},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'aggregate'},{'id': '195', 'type': 'argument_list', 'children': ['196', '202', '209', '215']},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'time_spent'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'Sum'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'string', 'children': [], 'value': '"response_time"'},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'sessions'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'Count'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208']},{'id': '207', 'type': 'string', 'children': [], 'value': '"session"'},{'id': '208', 'type': 'True', 'children': []},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'time_first'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'Min'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'string', 'children': [], 'value': '"time"'},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'time_last'},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'Max'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'string', 'children': [], 'value': '"time"'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '224', 'type': 'dictionary', 'children': ['225', '238', '251', '259', '275', '291', '312', '319', '324', '333']},{'id': '225', 'type': 'pair', 'children': ['226', '227']},{'id': '226', 'type': 'string', 'children': [], 'value': '"answer_count"'},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '229', 'type': 'generator_expression', 'children': ['230', '233']},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'answer_counts'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '233', 'type': 'for_in_clause', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '238', 'type': 'pair', 'children': ['239', '240']},{'id': '239', 'type': 'string', 'children': [], 'value': '"correct_answer_count"'},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '242', 'type': 'generator_expression', 'children': ['243', '246']},{'id': '243', 'type': 'subscript', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'correct_answer_counts'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '246', 'type': 'for_in_clause', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '248', 'type': 'subscript', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '251', 'type': 'pair', 'children': ['252', '253']},{'id': '252', 'type': 'string', 'children': [], 'value': '"item_count"'},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '259', 'type': 'pair', 'children': ['260', '261']},{'id': '260', 'type': 'string', 'children': [], 'value': '"practiced_items_count"'},{'id': '261', 'type': 'call', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'list_comprehension', 'children': ['265', '270']},{'id': '265', 'type': 'comparison_operator', 'children': ['266', '269'], 'value': '>'},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'answer_counts'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '269', 'type': 'integer', 'children': [], 'value': '0'},{'id': '270', 'type': 'for_in_clause', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '275', 'type': 'pair', 'children': ['276', '277']},{'id': '276', 'type': 'string', 'children': [], 'value': '"mastered_items_count"'},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'list_comprehension', 'children': ['281', '286']},{'id': '281', 'type': 'comparison_operator', 'children': ['282', '285'], 'value': '>='},{'id': '282', 'type': 'subscript', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'predictions'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'mastery_threshold'},{'id': '286', 'type': 'for_in_clause', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '291', 'type': 'pair', 'children': ['292', '293']},{'id': '292', 'type': 'string', 'children': [], 'value': '"prediction"'},{'id': '293', 'type': 'binary_operator', 'children': ['294', '306'], 'value': '/'},{'id': '294', 'type': 'call', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'list_comprehension', 'children': ['298', '301']},{'id': '298', 'type': 'subscript', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'predictions'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '301', 'type': 'for_in_clause', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'subscript', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '312', 'type': 'pair', 'children': ['313', '314']},{'id': '313', 'type': 'string', 'children': [], 'value': '"time_spent"'},{'id': '314', 'type': 'binary_operator', 'children': ['315', '318'], 'value': '/'},{'id': '315', 'type': 'subscript', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'answer_aggregates'},{'id': '317', 'type': 'string', 'children': [], 'value': '"time_spent"'},{'id': '318', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '319', 'type': 'pair', 'children': ['320', '321']},{'id': '320', 'type': 'string', 'children': [], 'value': '"session_count"'},{'id': '321', 'type': 'subscript', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'answer_aggregates'},{'id': '323', 'type': 'string', 'children': [], 'value': '"sessions"'},{'id': '324', 'type': 'pair', 'children': ['325', '326']},{'id': '325', 'type': 'string', 'children': [], 'value': '"time_first"'},{'id': '326', 'type': 'call', 'children': ['327', '332']},{'id': '327', 'type': 'attribute', 'children': ['328', '331']},{'id': '328', 'type': 'subscript', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'answer_aggregates'},{'id': '330', 'type': 'string', 'children': [], 'value': '"time_first"'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '332', 'type': 'argument_list', 'children': []},{'id': '333', 'type': 'pair', 'children': ['334', '335']},{'id': '334', 'type': 'string', 'children': [], 'value': '"time_last"'},{'id': '335', 'type': 'call', 'children': ['336', '341']},{'id': '336', 'type': 'attribute', 'children': ['337', '340']},{'id': '337', 'type': 'subscript', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'answer_aggregates'},{'id': '339', 'type': 'string', 'children': [], 'value': '"time_last"'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '341', 'type': 'argument_list', 'children': []},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'augmented_assignment', 'children': ['344', '345'], 'value': '|='},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'stats_to_delete_condition'},{'id': '345', 'type': 'call', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '347', 'type': 'argument_list', 'children': ['348', '351']},{'id': '348', 'type': 'keyword_argument', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '351', 'type': 'keyword_argument', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '354', 'type': 'for_statement', 'children': ['355', '358', '363']},{'id': '355', 'type': 'pattern_list', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'stat_name'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '358', 'type': 'call', 'children': ['359', '362']},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '362', 'type': 'argument_list', 'children': []},{'id': '363', 'type': 'block', 'children': ['364']},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'new_user_stats'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'UserStat'},{'id': '372', 'type': 'argument_list', 'children': ['373', '376', '379', '382']},{'id': '373', 'type': 'keyword_argument', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '376', 'type': 'keyword_argument', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'concept_id'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '379', 'type': 'keyword_argument', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'stat_name'},{'id': '382', 'type': 'keyword_argument', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '385', 'type': 'expression_statement', 'children': ['386']},{'id': '386', 'type': 'call', 'children': ['387', '395']},{'id': '387', 'type': 'attribute', 'children': ['388', '394']},{'id': '388', 'type': 'call', 'children': ['389', '392']},{'id': '389', 'type': 'attribute', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '392', 'type': 'argument_list', 'children': ['393']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'stats_to_delete_condition'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '395', 'type': 'argument_list', 'children': []},{'id': '396', 'type': 'expression_statement', 'children': ['397']},{'id': '397', 'type': 'call', 'children': ['398', '401']},{'id': '398', 'type': 'attribute', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'bulk_create'},{'id': '401', 'type': 'argument_list', 'children': ['402']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'new_user_stats'}
def recalculate_concepts(self, concepts, lang=None): if len(concepts) == 0: return if lang is None: items = Concept.objects.get_concept_item_mapping(concepts=Concept.objects.filter(pk__in=set(flatten(concepts.values())))) else: items = Concept.objects.get_concept_item_mapping(lang=lang) environment = get_environment() mastery_threshold = get_mastery_trashold() for user, concepts in concepts.items(): all_items = list(set(flatten([items[c] for c in concepts]))) answer_counts = environment.number_of_answers_more_items(all_items, user) correct_answer_counts = environment.number_of_correct_answers_more_items(all_items, user) predictions = dict(list(zip(all_items, get_predictive_model(). predict_more_items(environment, user, all_items, time=get_time_for_knowledge_overview())))) new_user_stats = [] stats_to_delete_condition = Q() for concept in concepts: answer_aggregates = Answer.objects.filter(user=user, item__in=items[concept]).aggregate( time_spent=Sum("response_time"), sessions=Count("session", True), time_first=Min("time"), time_last=Max("time"), ) stats = { "answer_count": sum(answer_counts[i] for i in items[concept]), "correct_answer_count": sum(correct_answer_counts[i] for i in items[concept]), "item_count": len(items[concept]), "practiced_items_count": sum([answer_counts[i] > 0 for i in items[concept]]), "mastered_items_count": sum([predictions[i] >= mastery_threshold for i in items[concept]]), "prediction": sum([predictions[i] for i in items[concept]]) / len(items[concept]), "time_spent": answer_aggregates["time_spent"] / 1000, "session_count": answer_aggregates["sessions"], "time_first": answer_aggregates["time_first"].timestamp(), "time_last": answer_aggregates["time_last"].timestamp(), } stats_to_delete_condition |= Q(user=user, concept=concept) for stat_name, value in stats.items(): new_user_stats.append(UserStat(user_id=user, concept_id=concept, stat=stat_name, value=value)) self.filter(stats_to_delete_condition).delete() self.bulk_create(new_user_stats)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_user_stats'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'since'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'recalculate'},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '23', '40', '112', '130', '146', '162', '178', '190', '214', '237']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'only_one_user'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'if_statement', 'children': ['24', '30']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '30', 'type': 'block', 'children': ['31', '36']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '34', 'type': 'list', 'children': ['35'], 'value': '[users]'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'only_one_user'},{'id': '39', 'type': 'True', 'children': []},{'id': '40', 'type': 'if_statement', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'recalculate'},{'id': '42', 'type': 'block', 'children': ['43', '53', '59', '72', '85', '91', '99']},{'id': '43', 'type': 'if_statement', 'children': ['44', '47']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'raise_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': "'Recalculation without lang is not supported.'"},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'time_start'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'time_lib'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'concepts_to_recalculate'},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'Concept'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'get_concepts_to_recalculate'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70', '71']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': '"user_stats - getting identifying concepts to recalculate: %ss"'},{'id': '79', 'type': '()', 'children': ['80']},{'id': '80', 'type': 'binary_operator', 'children': ['81', '84'], 'value': '-'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'time_lib'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'time_start'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'time_start'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'time_lib'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'recalculate_concepts'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'concepts_to_recalculate'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'lang'},{'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': 'LOGGER'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': '"user_stats - recalculating concepts: %ss"'},{'id': '106', 'type': '()', 'children': ['107']},{'id': '107', 'type': 'binary_operator', 'children': ['108', '111'], 'value': '-'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'time_lib'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'time_start'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '115', 'type': 'call', 'children': ['116', '123']},{'id': '116', 'type': 'attribute', 'children': ['117', '122']},{'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': 'prepare_related'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '123', 'type': 'argument_list', 'children': ['124', '127']},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'user__in'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'concept__active'},{'id': '129', 'type': 'True', 'children': []},{'id': '130', 'type': 'if_statement', 'children': ['131', '134']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'is'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '133', 'type': 'None', 'children': []},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'concept__in'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'concepts'},{'id': '146', 'type': 'if_statement', 'children': ['147', '150']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'is'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '149', 'type': 'None', 'children': []},{'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': 'qs'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'concept__lang'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '162', 'type': 'if_statement', 'children': ['163', '166']},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': 'is'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'since'},{'id': '165', 'type': 'None', 'children': []},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'time__gte'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'since'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'lambda', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'lambda', 'children': ['189']},{'id': '189', 'type': 'dictionary', 'children': []},{'id': '190', 'type': 'for_statement', 'children': ['191', '192', '193']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'user_stat'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '211']},{'id': '196', 'type': 'subscript', 'children': ['197', '208']},{'id': '197', 'type': 'subscript', 'children': ['198', '203']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'user_stat'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '203', 'type': 'attribute', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'user_stat'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'concept'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'user_stat'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'user_stat'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '214', 'type': 'if_statement', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'only_one_user'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'return_statement', 'children': ['218']},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '220', 'type': 'conditional_expression', 'children': ['221', '226', '234'], 'value': 'if'},{'id': '221', 'type': 'attribute', 'children': ['222', '225']},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '224', 'type': 'integer', 'children': [], 'value': '0'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '226', 'type': 'comparison_operator', 'children': ['227', '233'], 'value': '=='},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '232', 'type': 'integer', 'children': [], 'value': '0'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'User'},{'id': '234', 'type': 'subscript', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '236', 'type': 'integer', 'children': [], 'value': '0'},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'data'}
def get_user_stats(self, users, lang=None, concepts=None, since=None, recalculate=True): only_one_user = False if not isinstance(users, list): users = [users] only_one_user = True if recalculate: if lang is None: raise ValueError('Recalculation without lang is not supported.') time_start = time_lib() concepts_to_recalculate = Concept.objects.get_concepts_to_recalculate(users, lang, concepts) LOGGER.debug("user_stats - getting identifying concepts to recalculate: %ss", (time_lib() - time_start)) time_start = time_lib() self.recalculate_concepts(concepts_to_recalculate, lang) LOGGER.debug("user_stats - recalculating concepts: %ss", (time_lib() - time_start)) qs = self.prepare_related().filter(user__in=users, concept__active=True) if concepts is not None: qs = qs.filter(concept__in=concepts) if lang is not None: qs = qs.filter(concept__lang=lang) if since is not None: qs = qs.filter(time__gte=since) data = defaultdict(lambda: defaultdict(lambda: {})) for user_stat in qs: data[user_stat.user_id][user_stat.concept.identifier][user_stat.stat] = user_stat.value if only_one_user: return data[users[0].pk if type(users[0]) == User else users[0]] return data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'execute'},{'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': 'sql'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'cursorClass'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'DictCursor'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'do_commit'},{'id': '20', 'type': 'True', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '26', '30', '34', '38', '66', '332', '382']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'errcode'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'caughte'},{'id': '33', 'type': 'None', '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': 'None', 'children': []},{'id': '38', 'type': 'if_statement', 'children': ['39', '58']},{'id': '39', 'type': 'boolean_operator', 'children': ['40', '49'], 'value': 'or'},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '47'], 'value': '!='},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': '";"'},{'id': '47', 'type': 'unary_operator', 'children': ['48'], 'value': '-'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '56'], 'value': '!='},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'string', 'children': [], 'value': '"\\\\G"'},{'id': '56', 'type': 'unary_operator', 'children': ['57'], 'value': '-'},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'raise_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '%'},{'id': '64', 'type': 'string', 'children': [], 'value': '"The SQL command \'%s\' contains a semi-colon or \\\\G. This is a potential SQL injection."'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '66', 'type': 'while_statement', 'children': ['67', '72']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '<'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'numTries'},{'id': '72', 'type': 'block', 'children': ['73', '77', '327']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'augmented_assignment', 'children': ['75', '76'], 'value': '+='},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'try_statement', 'children': ['78', '219', '274']},{'id': '78', 'type': 'block', 'children': ['79', '94', '101', '111', '129', '153', '164', '179', '187', '205', '211', '217']},{'id': '79', 'type': 'assert_statement', 'children': ['80']},{'id': '80', 'type': '()', 'children': ['81']},{'id': '81', 'type': 'boolean_operator', 'children': ['82', '87'], 'value': 'or'},{'id': '82', 'type': 'not_operator', 'children': ['83']},{'id': '83', 'type': '()', 'children': ['84']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '87', 'type': 'not_operator', 'children': ['88']},{'id': '88', 'type': '()', 'children': ['89']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'open'},{'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': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_get_connection'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'cursorClass'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'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': 'connection'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'if_statement', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '113', 'type': 'block', 'children': ['114', '123']},{'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': 'cursor'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'lockstring'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '128', 'type': 'True', 'children': []},{'id': '129', 'type': 'if_statement', 'children': ['130', '131', '142']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'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': 'errcode'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '142', 'type': 'else_clause', 'children': ['143']},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'errcode'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'lastrowid'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'lastrowid'},{'id': '164', 'type': 'if_statement', 'children': ['165', '170']},{'id': '165', 'type': 'boolean_operator', 'children': ['166', '167'], 'value': 'and'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'do_commit'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'isInnoDB'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '178']},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'fetchall'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'if_statement', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '189', 'type': 'block', 'children': ['190', '199']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'unlockstring'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '204', 'type': 'False', 'children': []},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '210', 'type': 'argument_list', 'children': []},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': '_close_connection'},{'id': '216', 'type': 'argument_list', 'children': []},{'id': '217', 'type': 'return_statement', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '219', 'type': 'except_clause', 'children': ['220', '223', '224']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'MySQLdb'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'OperationalError'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '224', 'type': 'block', 'children': ['225', '254', '260', '267', '273']},{'id': '225', 'type': 'if_statement', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '227', 'type': 'block', 'children': ['228', '248']},{'id': '228', 'type': 'if_statement', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '232', 'type': 'block', 'children': ['233', '242']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'unlockstring'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '247', 'type': 'False', 'children': []},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '253', 'type': 'argument_list', 'children': []},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': '_close_connection'},{'id': '259', 'type': 'argument_list', 'children': []},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'caughte'},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'errcode'},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '272', 'type': 'integer', 'children': [], 'value': '0'},{'id': '273', 'type': 'continue_statement', 'children': []},{'id': '274', 'type': 'except_clause', 'children': ['275', '276', '277']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '277', 'type': 'block', 'children': ['278', '307', '313', '320', '326']},{'id': '278', 'type': 'if_statement', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '280', 'type': 'block', 'children': ['281', '301']},{'id': '281', 'type': 'if_statement', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '285', 'type': 'block', 'children': ['286', '295']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'unlockstring'},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '300', 'type': 'False', 'children': []},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '306', 'type': 'argument_list', 'children': []},{'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': 'self'},{'id': '311', 'type': 'identifier', 'children': [], 'value': '_close_connection'},{'id': '312', 'type': 'argument_list', 'children': []},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'assignment', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'caughte'},{'id': '316', 'type': 'call', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'e'},{'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': 'traceback'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'print_exc'},{'id': '325', 'type': 'argument_list', 'children': []},{'id': '326', 'type': 'break_statement', 'children': []},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'call', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'float', 'children': [], 'value': '0.2'},{'id': '332', 'type': 'if_statement', 'children': ['333', '335']},{'id': '333', 'type': 'not_operator', 'children': ['334']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'quiet'},{'id': '335', 'type': 'block', 'children': ['336', '358', '374']},{'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': 'sys'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '343', 'type': 'argument_list', 'children': ['344']},{'id': '344', 'type': 'binary_operator', 'children': ['345', '346'], 'value': '%'},{'id': '345', 'type': 'string', 'children': [], 'value': '"\\nSQL execution error in query %s at %s:"'},{'id': '346', 'type': 'tuple', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '348', 'type': 'call', 'children': ['349', '356']},{'id': '349', 'type': 'attribute', 'children': ['350', '355']},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '354', 'type': 'argument_list', 'children': []},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': 'string', 'children': [], 'value': '"%Y-%m-%d %H:%M:%S"'},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'call', 'children': ['360', '365']},{'id': '360', 'type': 'attribute', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '365', 'type': 'argument_list', 'children': ['366']},{'id': '366', 'type': 'binary_operator', 'children': ['367', '368'], 'value': '%'},{'id': '367', 'type': 'string', 'children': [], 'value': '"\\nErrorcode/Error: %d - \'%s\'.\\n"'},{'id': '368', 'type': 'tuple', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'errcode'},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '372', 'type': 'argument_list', 'children': ['373']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'caughte'},{'id': '374', 'type': 'expression_statement', 'children': ['375']},{'id': '375', 'type': 'call', 'children': ['376', '381']},{'id': '376', 'type': 'attribute', 'children': ['377', '380']},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '381', 'type': 'argument_list', 'children': []},{'id': '382', 'type': 'raise_statement', 'children': ['383']},{'id': '383', 'type': 'call', 'children': ['384', '387']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'MySQLdb'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'OperationalError'},{'id': '387', 'type': 'argument_list', 'children': ['388']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'caughte'}
def execute(self, sql, parameters = None, cursorClass = DictCursor, quiet = False, locked = False, do_commit = True): i = 0 errcode = 0 caughte = None cursor = None if sql.find(";") != -1 or sql.find("\\G") != -1: raise Exception("The SQL command '%s' contains a semi-colon or \\G. This is a potential SQL injection." % sql) while i < self.numTries: i += 1 try: assert(not(self.connection) or not(self.connection.open)) self._get_connection(cursorClass) cursor = self.connection.cursor() if locked: cursor.execute(self.lockstring) self.locked = True if parameters: errcode = cursor.execute(sql, parameters) else: errcode = cursor.execute(sql) self.lastrowid = int(cursor.lastrowid) if do_commit and self.isInnoDB: self.connection.commit() results = cursor.fetchall() if locked: cursor.execute(self.unlockstring) self.locked = False cursor.close() self._close_connection() return results except MySQLdb.OperationalError, e: if cursor: if self.locked: cursor.execute(self.unlockstring) self.locked = False cursor.close() self._close_connection() caughte = str(e) errcode = e[0] continue except Exception, e: if cursor: if self.locked: cursor.execute(self.unlockstring) self.locked = False cursor.close() self._close_connection() caughte = str(e) traceback.print_exc() break sleep(0.2) if not quiet: sys.stderr.write("\nSQL execution error in query %s at %s:" % (sql, datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) sys.stderr.write("\nErrorcode/Error: %d - '%s'.\n" % (errcode, str(caughte))) sys.stderr.flush() raise MySQLdb.OperationalError(caughte)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_tasks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'task_coro'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'addrs'},{'id': '6', 'type': 'list_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '13', 'type': 'block', 'children': ['14', '16', '20', '47']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': "'''Create and schedule a set of asynchronous tasks.\n The function creates the tasks using a given list of agent addresses and\n wraps each of them in :func:`asyncio.ensure_future`. The ``*args`` and\n ``**kwargs`` are passed down to :func:`task_coro` when creating tasks for\n each address in :attr:`addrs`.\n Usage example for a method in a class derived from\n :class:`~creamas.mp.MultiEnvironment`::\n async def my_method(self, *args, **kwargs):\n async def task(addr, *args, **kwargs):\n r_manager = await self.env.connect(addr)\n return await r_manager.my_method(*args, **kwargs)\n return await util.create_tasks(task, self.addrs, *args, **kwargs)\n :param task_coro:\n Coroutine which is used for each address in :attr:`addrs`. The\n coroutine should accept an agent address as the first parameter.\n :param list addrs:\n A list of agent addresses used as the first parameters of\n :func:`task_coro`.\n :param bool flatten:\n If ``True`` the returned results are flattened into one list if the\n tasks return iterable objects. The parameter does nothing if all the\n results are not iterable.\n :returns:\n An awaitable coroutine which returns the results of tasks as a list or\n as a flattened list\n '''"},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tasks'},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'agent_addr'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'addrs'},{'id': '23', 'type': 'block', 'children': ['24', '40']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ensure_future'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'task_coro'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36', '38']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'agent_addr'},{'id': '36', 'type': 'list_splat', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '38', 'type': 'dictionary_splat', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'tasks'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'wait_tasks'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'tasks'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'flatten'}
def create_tasks(task_coro, addrs, *args, flatten=True, **kwargs): '''Create and schedule a set of asynchronous tasks. The function creates the tasks using a given list of agent addresses and wraps each of them in :func:`asyncio.ensure_future`. The ``*args`` and ``**kwargs`` are passed down to :func:`task_coro` when creating tasks for each address in :attr:`addrs`. Usage example for a method in a class derived from :class:`~creamas.mp.MultiEnvironment`:: async def my_method(self, *args, **kwargs): async def task(addr, *args, **kwargs): r_manager = await self.env.connect(addr) return await r_manager.my_method(*args, **kwargs) return await util.create_tasks(task, self.addrs, *args, **kwargs) :param task_coro: Coroutine which is used for each address in :attr:`addrs`. The coroutine should accept an agent address as the first parameter. :param list addrs: A list of agent addresses used as the first parameters of :func:`task_coro`. :param bool flatten: If ``True`` the returned results are flattened into one list if the tasks return iterable objects. The parameter does nothing if all the results are not iterable. :returns: An awaitable coroutine which returns the results of tasks as a list or as a flattened list ''' tasks = [] for agent_addr in addrs: task = asyncio.ensure_future(task_coro(agent_addr, *args, **kwargs)) tasks.append(task) return wait_tasks(tasks, flatten)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'ERROR', 'children': ['2', '204']},{'id': '2', 'type': 'function_definition', 'children': ['3', '4', '21']},{'id': '3', 'type': 'function_name', 'children': [], 'value': 'write'},{'id': '4', 'type': 'parameters', 'children': ['5', '6', '9', '12', '15', '18']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'propertybase'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'shorteners'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '21', 'type': 'block', 'children': ['22', '24', '28', '41', '47', '55', '62', '197']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "'''\n models - input Versa models from which output is generated. Must be a sequence\n object, not an iterator\n '''"},{'id': '24', 'type': 'assert_statement', 'children': ['25']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'if_statement', 'children': ['29', '35']},{'id': '29', 'type': 'not_operator', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '39', 'type': 'list', 'children': ['40'], 'value': '[models]'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'shorteners'},{'id': '44', 'type': 'boolean_operator', 'children': ['45', '46'], 'value': 'or'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'shorteners'},{'id': '46', 'type': 'dictionary', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'all_propertybase'},{'id': '50', 'type': 'conditional_expression', 'children': ['51', '53', '54'], 'value': 'if'},{'id': '51', 'type': 'list', 'children': ['52'], 'value': '[propertybase]'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'propertybase'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'propertybase'},{'id': '54', 'type': 'list', 'children': [], 'value': '[]'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'all_propertybase'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'VERSA_BASEIRI'},{'id': '62', 'type': 'if_statement', 'children': ['63', '70', '133']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'tuple', 'children': ['67', '68', '69']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'propertybase'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'shorteners'},{'id': '70', 'type': 'ERROR', 'children': ['71', '74', '94', '95', '117', '120', '122', '123', '124', '125']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '74', 'type': 'ERROR', 'children': ['75', '76', '77', '88']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'if'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': "' * @base: {0}'"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': "'\\n\\n'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'origin_space'},{'id': '95', 'type': 'ERROR', 'children': ['96', '104', '113', '114']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '100', '103'], 'value': 'in'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '99', 'type': 'argument_list', 'children': []},{'id': '100', 'type': 'ERROR', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'for'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'origin_space'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'all_origins'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'for'},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'in'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'origin_space'},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '120', 'type': 'ERROR', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'for'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'o_'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'in'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '133', 'type': 'block', 'children': ['134', '142', '147', '163']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'abbr_r'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'abbreviate'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'all_propertybase'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'value_format'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 't'},{'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': 'out'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'string', 'children': [], 'value': "'* {0}: {1}\\n'"},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'abbr_r'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'value_format'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '163', 'type': 'for_statement', 'children': ['164', '167', '172']},{'id': '164', 'type': 'pattern_list', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '171', 'type': 'argument_list', 'children': []},{'id': '172', 'type': 'block', 'children': ['173', '181']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'abbr_k'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'abbreviate'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'all_propertybase'},{'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': 'out'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'string', 'children': [], 'value': "' * {0}: {1}\\n'"},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'value_format'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'v'},{'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': 'out'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '204', 'type': 'return_statement', 'children': []}
def write(models, out=None, base=None, propertybase=None, shorteners=None, logger=logging): ''' models - input Versa models from which output is generated. Must be a sequence object, not an iterator ''' assert out is not None if not isinstance(models, list): models = [models] shorteners = shorteners or {} all_propertybase = [propertybase] if propertybase else [] all_propertybase.append(VERSA_BASEIRI) if any((base, propertybase, shorteners)): out.write(' if base: out.write(' * @base: {0}'.format(base)) out.write('\n\n') origin_space = set() for m in models: origin_space.update(all_origins(m)) for o in origin_space: out.write(' for o_, r, t, a in m.match(o): abbr_r = abbreviate(r, all_propertybase) value_format(t) out.write('* {0}: {1}\n'.format(abbr_r, value_format(t))) for k, v in a.items(): abbr_k = abbreviate(k, all_propertybase) out.write(' * {0}: {1}\n'.format(k, value_format(v))) out.write('\n') return
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'register_extensions'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'try_statement', 'children': ['7', '159']},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'for_statement', 'children': ['9', '12', '21']},{'id': '9', 'type': 'pattern_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '12', 'type': 'call', 'children': ['13', '20']},{'id': '13', 'type': 'attribute', 'children': ['14', '19']},{'id': '14', 'type': 'subscript', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '18', 'type': 'string', 'children': [], 'value': "'extensions'"},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '26', '35', '62', '69']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'extension_bstr'},{'id': '25', 'type': 'string', 'children': [], 'value': "''"},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'extension_pieces'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '35', 'type': 'if_statement', 'children': ['36', '42', '52']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '41'], 'value': '>'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'extension_pieces'},{'id': '41', 'type': 'integer', 'children': [], 'value': '1'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'extension_bstr'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'extension_pieces'},{'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': 'extension_bstr'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '%'},{'id': '58', 'type': 'string', 'children': [], 'value': "'glim_extensions.%s'"},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'extension_pieces'},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'extension_module'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'import_module'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'extension_bstr'},{'id': '69', 'type': 'if_statement', 'children': ['70', '71', '148']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'extension_module'},{'id': '71', 'type': 'block', 'children': ['72', '80', '90', '98', '108', '124']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'extension_startstr'},{'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '%'},{'id': '76', 'type': 'string', 'children': [], 'value': "'%s.%s'"},{'id': '77', 'type': 'tuple', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'extension_bstr'},{'id': '79', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'extension_start'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'import_module'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'extension_startstr'},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'pass_errors'},{'id': '89', 'type': 'True', 'children': []},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'extension_cmdsstr'},{'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '%'},{'id': '94', 'type': 'string', 'children': [], 'value': "'%s.%s'"},{'id': '95', 'type': 'tuple', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'extension_bstr'},{'id': '97', 'type': 'string', 'children': [], 'value': "'commands'"},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'extension_cmds'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'import_module'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'extension_cmdsstr'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'pass_errors'},{'id': '107', 'type': 'True', 'children': []},{'id': '108', 'type': 'if_statement', 'children': ['109', '112']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'is'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'extension_start'},{'id': '111', 'type': 'None', 'children': []},{'id': '112', 'type': 'block', 'children': ['113', '119']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'extension_start'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '124', 'type': 'if_statement', 'children': ['125', '128']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'extension_cmds'},{'id': '127', 'type': 'None', 'children': []},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'if_statement', 'children': ['130', '135']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '134'], 'value': 'is'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'commandadapter'},{'id': '134', 'type': 'None', 'children': []},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '143']},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'commandadapter'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'register_extension'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'extension_cmds'},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'extension_pieces'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'else_clause', 'children': ['149']},{'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': 'GlimLog'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '%'},{'id': '157', 'type': 'string', 'children': [], 'value': "'Extension %s could not be loaded'"},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '159', 'type': 'except_clause', 'children': ['160', '164']},{'id': '160', 'type': 'as_pattern', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '162', 'type': 'as_pattern_target', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'GlimLog'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'traceback'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'format_exc'},{'id': '175', 'type': 'argument_list', 'children': []}
def register_extensions(self): try: for extension, config in self.config['extensions'].items(): extension_bstr = '' extension_pieces = extension.split('.') if len(extension_pieces) > 1: extension_bstr = '.'.join(extension_pieces) else: extension_bstr = 'glim_extensions.%s' % extension_pieces[0] extension_module = import_module(extension_bstr) if extension_module: extension_startstr = '%s.%s' % (extension_bstr, 'start') extension_start = import_module(extension_startstr, pass_errors=True) extension_cmdsstr = '%s.%s' % (extension_bstr, 'commands') extension_cmds = import_module(extension_cmdsstr, pass_errors=True) if extension_start is not None: before = extension_start.before before(config) if extension_cmds is not None: if self.commandadapter is not None: self.commandadapter.register_extension(extension_cmds, extension_pieces[0]) else: GlimLog.error('Extension %s could not be loaded' % extension) except Exception as e: GlimLog.error(traceback.format_exc())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'request'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '12', 'type': 'dictionary', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '15', 'type': 'dictionary', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '22', '34', '45', '58', '86', '103', '125', '265']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': "'''\n Issues a request to Onshape\n Args:\n - method (str): HTTP method\n - path (str): Path e.g. /api/documents/:id\n - query (dict, default={}): Query params in key-value pairs\n - headers (dict, default={}): Key-value pairs of headers\n - body (dict, default={}): Body for POST request\n - base_url (str, default=None): Host, including scheme and port (if different from creds file)\n Returns:\n - requests.Response: Object containing the response from Onshape\n '''"},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'req_headers'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_make_headers'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32', '33']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_url'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '48', 'type': 'binary_operator', 'children': ['49', '54'], 'value': '+'},{'id': '49', 'type': 'binary_operator', 'children': ['50', '53'], 'value': '+'},{'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '+'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '53', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '58', 'type': 'if_statement', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_logging'},{'id': '62', 'type': 'block', 'children': ['63', '70', '77']},{'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': 'utils'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'req_headers'},{'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': 'utils'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '+'},{'id': '84', 'type': 'string', 'children': [], 'value': "'request url: '"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '89', 'type': 'conditional_expression', 'children': ['90', '96', '102'], 'value': 'if'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '101'], 'value': '=='},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112', '113', '116', '119', '122']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'req_headers'},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'allow_redirects'},{'id': '121', 'type': 'False', 'children': []},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '124', 'type': 'True', 'children': []},{'id': '125', 'type': 'if_statement', 'children': ['126', '131', '219', '247']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '=='},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '130', 'type': 'integer', 'children': [], 'value': '307'},{'id': '131', 'type': 'block', 'children': ['132', '143', '152', '170', '174', '186', '200']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'subscript', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '142', 'type': 'string', 'children': [], 'value': '"Location"'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'querystring'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'parse_qs'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '152', 'type': 'if_statement', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': '_logging'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '+'},{'id': '164', 'type': 'string', 'children': [], 'value': "'request redirected to: '"},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'geturl'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'new_query'},{'id': '173', 'type': 'dictionary', 'children': []},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'new_base_url'},{'id': '177', 'type': 'binary_operator', 'children': ['178', '183'], 'value': '+'},{'id': '178', 'type': 'binary_operator', 'children': ['179', '182'], 'value': '+'},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '182', 'type': 'string', 'children': [], 'value': "'://'"},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'netloc'},{'id': '186', 'type': 'for_statement', 'children': ['187', '188', '189']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'querystring'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '195']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'new_query'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '195', 'type': 'subscript', 'children': ['196', '199']},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'querystring'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '199', 'type': 'integer', 'children': [], 'value': '0'},{'id': '200', 'type': 'return_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207', '210', '213', '216']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'new_query'},{'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'new_base_url'},{'id': '219', 'type': 'elif_clause', 'children': ['220', '227']},{'id': '220', 'type': 'not_operator', 'children': ['221']},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '223', '226'], 'value': '<='},{'id': '222', 'type': 'integer', 'children': [], 'value': '200'},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '226', 'type': 'integer', 'children': [], 'value': '206'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'if_statement', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '231', 'type': 'identifier', 'children': [], 'value': '_logging'},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '238', 'type': 'argument_list', 'children': ['239', '244']},{'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '+'},{'id': '240', 'type': 'string', 'children': [], 'value': "'request failed, details: '"},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '246', 'type': 'integer', 'children': [], 'value': '1'},{'id': '247', 'type': 'else_clause', 'children': ['248']},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'if_statement', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '252', 'type': 'identifier', 'children': [], 'value': '_logging'},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'binary_operator', 'children': ['261', '262'], 'value': '+'},{'id': '261', 'type': 'string', 'children': [], 'value': "'request succeeded, details: '"},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '265', 'type': 'return_statement', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'res'}
def request(self, method, path, query={}, headers={}, body={}, base_url=None): ''' Issues a request to Onshape Args: - method (str): HTTP method - path (str): Path e.g. /api/documents/:id - query (dict, default={}): Query params in key-value pairs - headers (dict, default={}): Key-value pairs of headers - body (dict, default={}): Body for POST request - base_url (str, default=None): Host, including scheme and port (if different from creds file) Returns: - requests.Response: Object containing the response from Onshape ''' req_headers = self._make_headers(method, path, query, headers) if base_url is None: base_url = self._url url = base_url + path + '?' + urlencode(query) if self._logging: utils.log(body) utils.log(req_headers) utils.log('request url: ' + url) body = json.dumps(body) if type(body) == dict else body res = requests.request(method, url, headers=req_headers, data=body, allow_redirects=False, stream=True) if res.status_code == 307: location = urlparse(res.headers["Location"]) querystring = parse_qs(location.query) if self._logging: utils.log('request redirected to: ' + location.geturl()) new_query = {} new_base_url = location.scheme + '://' + location.netloc for key in querystring: new_query[key] = querystring[key][0] return self.request(method, location.path, query=new_query, headers=headers, base_url=new_base_url) elif not 200 <= res.status_code <= 206: if self._logging: utils.log('request failed, details: ' + res.text, level=1) else: if self._logging: utils.log('request succeeded, details: ' + res.text) return res
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fix_pdb'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '14', '20', '50']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''A function to fix fatal errors in PDB files when they can be automatically fixed. At present, this only runs if\n self.strict is False. We may want a separate property for this since we may want to keep strict mode but still\n allow PDBs to be fixed.\n The only fixes at the moment are for missing chain IDs which get filled in with a valid PDB ID, if possible.'''"},{'id': '8', 'type': 'if_statement', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'chains'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '25']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '40']},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '34'], 'value': 'or'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'string', 'children': [], 'value': "'ATOM '"},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': "'HETATM'"},{'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': 'chains'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '49', 'type': 'integer', 'children': [], 'value': '21'},{'id': '50', 'type': 'if_statement', 'children': ['51', '54']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'in'},{'id': '52', 'type': 'string', 'children': [], 'value': "' '"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'chains'},{'id': '54', 'type': 'block', 'children': ['55', '59', '84', '100', '109', '113']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'fresh_id'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'allowed_chain_ids'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '76'], 'value': '+'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '70'], 'value': '+'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'uppercase'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'lowercase'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'integer', 'children': [], 'value': '10'},{'id': '84', 'type': 'for_statement', 'children': ['85', '86', '87']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'chains'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'try_statement', 'children': ['89', '97']},{'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': 'allowed_chain_ids'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '97', 'type': 'except_clause', 'children': ['98']},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'pass_statement', 'children': []},{'id': '100', 'type': 'if_statement', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'allowed_chain_ids'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'fresh_id'},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'allowed_chain_ids'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'new_lines'},{'id': '112', 'type': 'list', 'children': [], 'value': '[]'},{'id': '113', 'type': 'if_statement', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'fresh_id'},{'id': '115', 'type': 'block', 'children': ['116', '173']},{'id': '116', 'type': 'for_statement', 'children': ['117', '118', '121']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'if_statement', 'children': ['123', '143', '164']},{'id': '123', 'type': 'boolean_operator', 'children': ['124', '138'], 'value': 'and'},{'id': '124', 'type': '()', 'children': ['125']},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '132'], 'value': 'or'},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'string', 'children': [], 'value': "'ATOM '"},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'string', 'children': [], 'value': "'HETATM'"},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '142'], 'value': '=='},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '141', 'type': 'integer', 'children': [], 'value': '21'},{'id': '142', 'type': 'string', 'children': [], 'value': "' '"},{'id': '143', 'type': 'block', 'children': ['144']},{'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': 'new_lines'},{'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': "'%s%s%s'"},{'id': '152', 'type': 'tuple', 'children': ['153', '158', '159']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '155', 'type': 'slice', 'children': ['156', '157']},{'id': '156', 'type': 'colon', 'children': []},{'id': '157', 'type': 'integer', 'children': [], 'value': '21'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'fresh_id'},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '161', 'type': 'slice', 'children': ['162', '163']},{'id': '162', 'type': 'integer', 'children': [], 'value': '22'},{'id': '163', 'type': 'colon', 'children': []},{'id': '164', 'type': 'else_clause', 'children': ['165']},{'id': '165', 'type': 'block', 'children': ['166']},{'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': 'new_lines'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'l'},{'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': 'lines'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'new_lines'}
def fix_pdb(self): '''A function to fix fatal errors in PDB files when they can be automatically fixed. At present, this only runs if self.strict is False. We may want a separate property for this since we may want to keep strict mode but still allow PDBs to be fixed. The only fixes at the moment are for missing chain IDs which get filled in with a valid PDB ID, if possible.''' if self.strict: return chains = set() for l in self.lines: if l.startswith('ATOM ') or l.startswith('HETATM'): chains.add(l[21]) if ' ' in chains: fresh_id = None allowed_chain_ids = list(string.uppercase) + list(string.lowercase) + map(str, range(10)) for c in chains: try: allowed_chain_ids.remove(c) except: pass if allowed_chain_ids: fresh_id = allowed_chain_ids[0] new_lines = [] if fresh_id: for l in self.lines: if (l.startswith('ATOM ') or l.startswith('HETATM')) and l[21] == ' ': new_lines.append('%s%s%s' % (l[:21], fresh_id, l[22:])) else: new_lines.append(l) self.lines = new_lines
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'stripForDDG'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'chains'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'keepHETATM'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'numberOfModels'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'raise_exception'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '20', '28', '34', '38', '42', '46', '50', '54', '58', '263', '269', '275', '281', '285', '296', '304', '319', '325', '331', '341', '348', '352', '364', '369']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'''Strips a PDB to ATOM lines. If keepHETATM is True then also retain HETATM lines.\n By default all PDB chains are kept. The chains parameter should be True or a list.\n In the latter case, only those chains in the list are kept.\n Unoccupied ATOM lines are discarded.\n This function also builds maps from PDB numbering to Rosetta numbering and vice versa.\n '''"},{'id': '20', 'type': 'if_statement', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'raise_exception'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': "'This code is deprecated.'"},{'id': '28', 'type': 'import_from_statement', 'children': ['29', '32']},{'id': '29', 'type': 'dotted_name', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'Bio'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'PDB'},{'id': '32', 'type': 'dotted_name', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'PDBParser'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'resmap'},{'id': '37', 'type': 'dictionary', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'iresmap'},{'id': '41', 'type': 'dictionary', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'newlines'},{'id': '45', 'type': 'list', 'children': [], 'value': '[]'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'residx'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'oldres'},{'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': 'model_number'},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'for_statement', 'children': ['59', '60', '63']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '63', 'type': 'block', 'children': ['64', '77', '104']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'fieldtype'},{'id': '67', 'type': 'call', 'children': ['68', '76']},{'id': '68', 'type': 'attribute', 'children': ['69', '75']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '71', 'type': 'slice', 'children': ['72', '73', '74']},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'colon', 'children': []},{'id': '74', 'type': 'integer', 'children': [], 'value': '6'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'if_statement', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '=='},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'fieldtype'},{'id': '80', 'type': 'string', 'children': [], 'value': '"ENDMDL"'},{'id': '81', 'type': 'block', 'children': ['82', '86', '95']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'augmented_assignment', 'children': ['84', '85'], 'value': '+='},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'model_number'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'if_statement', 'children': ['87', '93']},{'id': '87', 'type': 'boolean_operator', 'children': ['88', '89'], 'value': 'and'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'numberOfModels'},{'id': '89', 'type': '()', 'children': ['90']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '>'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'model_number'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'numberOfModels'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'break_statement', 'children': []},{'id': '95', 'type': 'if_statement', 'children': ['96', '98']},{'id': '96', 'type': 'not_operator', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'numberOfModels'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'raise_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'string', 'children': [], 'value': '"The logic here does not handle multiple models yet."'},{'id': '104', 'type': 'if_statement', 'children': ['105', '129']},{'id': '105', 'type': 'boolean_operator', 'children': ['106', '117'], 'value': 'and'},{'id': '106', 'type': '()', 'children': ['107']},{'id': '107', 'type': 'boolean_operator', 'children': ['108', '111'], 'value': 'or'},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '=='},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'fieldtype'},{'id': '110', 'type': 'string', 'children': [], 'value': '"ATOM"'},{'id': '111', 'type': '()', 'children': ['112']},{'id': '112', 'type': 'boolean_operator', 'children': ['113', '116'], 'value': 'and'},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '=='},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'fieldtype'},{'id': '115', 'type': 'string', 'children': [], 'value': '"HETATM"'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'keepHETATM'},{'id': '117', 'type': '()', 'children': ['118']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '128'], 'value': '!='},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '124', 'type': 'slice', 'children': ['125', '126', '127']},{'id': '125', 'type': 'integer', 'children': [], 'value': '54'},{'id': '126', 'type': 'colon', 'children': []},{'id': '127', 'type': 'integer', 'children': [], 'value': '60'},{'id': '128', 'type': 'integer', 'children': [], 'value': '0'},{'id': '129', 'type': 'block', 'children': ['130', '139']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '135', 'type': 'slice', 'children': ['136', '137', '138']},{'id': '136', 'type': 'integer', 'children': [], 'value': '21'},{'id': '137', 'type': 'colon', 'children': []},{'id': '138', 'type': 'integer', 'children': [], 'value': '22'},{'id': '139', 'type': 'if_statement', 'children': ['140', '149']},{'id': '140', 'type': 'boolean_operator', 'children': ['141', '145'], 'value': 'or'},{'id': '141', 'type': '()', 'children': ['142']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '=='},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'chains'},{'id': '144', 'type': 'True', 'children': []},{'id': '145', 'type': '()', 'children': ['146']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': 'in'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'chains'},{'id': '149', 'type': 'block', 'children': ['150', '159', '168', '217', '224', '248', '256']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '155', 'type': 'slice', 'children': ['156', '157', '158']},{'id': '156', 'type': 'integer', 'children': [], 'value': '21'},{'id': '157', 'type': 'colon', 'children': []},{'id': '158', 'type': 'integer', 'children': [], 'value': '27'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'iCode'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '164', 'type': 'slice', 'children': ['165', '166', '167']},{'id': '165', 'type': 'integer', 'children': [], 'value': '26'},{'id': '166', 'type': 'colon', 'children': []},{'id': '167', 'type': 'integer', 'children': [], 'value': '27'},{'id': '168', 'type': 'if_statement', 'children': ['169', '172']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': '!='},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'oldres'},{'id': '172', 'type': 'block', 'children': ['173', '177', '185', '193', '201', '207', '213']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'augmented_assignment', 'children': ['175', '176'], 'value': '+='},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'residx'},{'id': '176', 'type': 'integer', 'children': [], 'value': '1'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'newnumbering'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '%'},{'id': '181', 'type': 'string', 'children': [], 'value': '"%s%4.i "'},{'id': '182', 'type': 'tuple', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'residx'},{'id': '185', 'type': 'assert_statement', 'children': ['186']},{'id': '186', 'type': '()', 'children': ['187']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '192'], 'value': '=='},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'newnumbering'},{'id': '192', 'type': 'integer', 'children': [], 'value': '6'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '196', 'type': 'binary_operator', 'children': ['197', '200'], 'value': '+'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '+'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'fieldtype'},{'id': '199', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '206']},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'resmap'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'residx'},{'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': 'iresmap'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'residx'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'oldres'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'oldlength'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '%'},{'id': '228', 'type': 'string', 'children': [], 'value': '"%s%4.i %s"'},{'id': '229', 'type': 'tuple', 'children': ['230', '236', '243']},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '232', 'type': 'slice', 'children': ['233', '234', '235']},{'id': '233', 'type': 'integer', 'children': [], 'value': '0'},{'id': '234', 'type': 'colon', 'children': []},{'id': '235', 'type': 'integer', 'children': [], 'value': '22'},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'resmap'},{'id': '238', 'type': 'binary_operator', 'children': ['239', '242'], 'value': '+'},{'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '+'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'fieldtype'},{'id': '241', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '243', 'type': 'subscript', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '245', 'type': 'slice', 'children': ['246', '247']},{'id': '246', 'type': 'integer', 'children': [], 'value': '27'},{'id': '247', 'type': 'colon', 'children': []},{'id': '248', 'type': 'assert_statement', 'children': ['249']},{'id': '249', 'type': '()', 'children': ['250']},{'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': 'line'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'oldlength'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'newlines'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'newlines'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'ddGresmap'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'resmap'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'ddGiresmap'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'iresmap'},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'tmpfile'},{'id': '284', 'type': 'string', 'children': [], 'value': '"/tmp/ddgtemp.pdb"'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '290', 'type': 'boolean_operator', 'children': ['291', '294'], 'value': 'or'},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '294', 'type': 'list', 'children': ['295'], 'value': '["\\n"]'},{'id': '295', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '299', 'type': 'call', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '301', 'type': 'argument_list', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'tmpfile'},{'id': '303', 'type': 'string', 'children': [], 'value': "'w'"},{'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': 'F'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '314', 'type': 'argument_list', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '318', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '324', 'type': 'argument_list', 'children': []},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'assignment', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '328', 'type': 'call', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'PDBParser'},{'id': '330', 'type': 'argument_list', 'children': []},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'assignment', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'structure'},{'id': '334', 'type': 'call', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'get_structure'},{'id': '338', 'type': 'argument_list', 'children': ['339', '340']},{'id': '339', 'type': 'string', 'children': [], 'value': "'tmp'"},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'tmpfile'},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'call', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'tmpfile'},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'assignment', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '351', 'type': 'integer', 'children': [], 'value': '0'},{'id': '352', 'type': 'for_statement', 'children': ['353', '354', '359']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '354', 'type': 'call', 'children': ['355', '358']},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'structure'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'get_residues'},{'id': '358', 'type': 'argument_list', 'children': []},{'id': '359', 'type': 'block', 'children': ['360']},{'id': '360', 'type': 'expression_statement', 'children': ['361']},{'id': '361', 'type': 'augmented_assignment', 'children': ['362', '363'], 'value': '+='},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '363', 'type': 'integer', 'children': [], 'value': '1'},{'id': '364', 'type': 'assert_statement', 'children': ['365']},{'id': '365', 'type': '()', 'children': ['366']},{'id': '366', 'type': 'comparison_operator', 'children': ['367', '368'], 'value': '=='},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'residx'},{'id': '369', 'type': 'assert_statement', 'children': ['370']},{'id': '370', 'type': '()', 'children': ['371']},{'id': '371', 'type': 'comparison_operator', 'children': ['372', '376'], 'value': '=='},{'id': '372', 'type': 'call', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '374', 'type': 'argument_list', 'children': ['375']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'resmap'},{'id': '376', 'type': 'call', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '378', 'type': 'argument_list', 'children': ['379']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'iresmap'}
def stripForDDG(self, chains = True, keepHETATM = False, numberOfModels = None, raise_exception = True): '''Strips a PDB to ATOM lines. If keepHETATM is True then also retain HETATM lines. By default all PDB chains are kept. The chains parameter should be True or a list. In the latter case, only those chains in the list are kept. Unoccupied ATOM lines are discarded. This function also builds maps from PDB numbering to Rosetta numbering and vice versa. ''' if raise_exception: raise Exception('This code is deprecated.') from Bio.PDB import PDBParser resmap = {} iresmap = {} newlines = [] residx = 0 oldres = None model_number = 1 for line in self.lines: fieldtype = line[0:6].strip() if fieldtype == "ENDMDL": model_number += 1 if numberOfModels and (model_number > numberOfModels): break if not numberOfModels: raise Exception("The logic here does not handle multiple models yet.") if (fieldtype == "ATOM" or (fieldtype == "HETATM" and keepHETATM)) and (float(line[54:60]) != 0): chain = line[21:22] if (chains == True) or (chain in chains): resid = line[21:27] iCode = line[26:27] if resid != oldres: residx += 1 newnumbering = "%s%4.i " % (chain, residx) assert(len(newnumbering) == 6) id = fieldtype + "-" + resid resmap[id] = residx iresmap[residx] = id oldres = resid oldlength = len(line) line = "%s%4.i %s" % (line[0:22], resmap[fieldtype + "-" + resid], line[27:]) assert(len(line) == oldlength) newlines.append(line) self.lines = newlines self.ddGresmap = resmap self.ddGiresmap = iresmap tmpfile = "/tmp/ddgtemp.pdb" self.lines = self.lines or ["\n"] F = open(tmpfile,'w') F.write(string.join(self.lines, "\n")) F.close() parser=PDBParser() structure=parser.get_structure('tmp', tmpfile) os.remove(tmpfile) count = 0 for residue in structure.get_residues(): count += 1 assert(count == residx) assert(len(resmap) == len(iresmap))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'neighbors2'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'chain_residue'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'resid_list'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '16', '76', '85', '133', '137', '218']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': "'''this one is more precise since it uses the chain identifier also'''"},{'id': '16', 'type': 'if_statement', 'children': ['17', '20', '43']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '=='},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '19', 'type': 'None', 'children': []},{'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': 'lines'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '26', '34']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'line'},{'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': 'atomlines'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'resid_list'},{'id': '34', 'type': 'if_clause', 'children': ['35']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '42'], 'value': 'in'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '38', 'type': 'slice', 'children': ['39', '40', '41']},{'id': '39', 'type': 'integer', 'children': [], 'value': '17'},{'id': '40', 'type': 'colon', 'children': []},{'id': '41', 'type': 'integer', 'children': [], 'value': '20'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'allowed_PDB_residues_types'},{'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', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '48', 'type': 'list_comprehension', 'children': ['49', '50', '58']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'atomlines'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'resid_list'},{'id': '58', 'type': 'if_clause', 'children': ['59']},{'id': '59', 'type': 'boolean_operator', 'children': ['60', '68'], 'value': 'and'},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '67'], 'value': 'in'},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '63', 'type': 'slice', 'children': ['64', '65', '66']},{'id': '64', 'type': 'integer', 'children': [], 'value': '17'},{'id': '65', 'type': 'colon', 'children': []},{'id': '66', 'type': 'integer', 'children': [], 'value': '20'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'allowed_PDB_residues_types'},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '75'], 'value': '=='},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '71', 'type': 'slice', 'children': ['72', '73', '74']},{'id': '72', 'type': 'integer', 'children': [], 'value': '12'},{'id': '73', 'type': 'colon', 'children': []},{'id': '74', 'type': 'integer', 'children': [], 'value': '16'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'shash'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'spatialhash'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'SpatialHash'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '85', 'type': 'for_statement', 'children': ['86', '87', '88']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '88', 'type': 'block', 'children': ['89', '120']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '92', 'type': 'tuple', 'children': ['93', '102', '111']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '98', 'type': 'slice', 'children': ['99', '100', '101']},{'id': '99', 'type': 'integer', 'children': [], 'value': '30'},{'id': '100', 'type': 'colon', 'children': []},{'id': '101', 'type': 'integer', 'children': [], 'value': '38'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '107', 'type': 'slice', 'children': ['108', '109', '110']},{'id': '108', 'type': 'integer', 'children': [], 'value': '38'},{'id': '109', 'type': 'colon', 'children': []},{'id': '110', 'type': 'integer', 'children': [], 'value': '46'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '116', 'type': 'slice', 'children': ['117', '118', '119']},{'id': '117', 'type': 'integer', 'children': [], 'value': '46'},{'id': '118', 'type': 'colon', 'children': []},{'id': '119', 'type': 'integer', 'children': [], 'value': '54'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'shash'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '129', 'type': 'slice', 'children': ['130', '131', '132']},{'id': '130', 'type': 'integer', 'children': [], 'value': '21'},{'id': '131', 'type': 'colon', 'children': []},{'id': '132', 'type': 'integer', 'children': [], 'value': '26'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'neighbor_list'},{'id': '136', 'type': 'list', 'children': [], 'value': '[]'},{'id': '137', 'type': 'for_statement', 'children': ['138', '139', '140']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '140', 'type': 'block', 'children': ['141', '150']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '146', 'type': 'slice', 'children': ['147', '148', '149']},{'id': '147', 'type': 'integer', 'children': [], 'value': '21'},{'id': '148', 'type': 'colon', 'children': []},{'id': '149', 'type': 'integer', 'children': [], 'value': '26'},{'id': '150', 'type': 'if_statement', 'children': ['151', '154']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': '=='},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'chain_residue'},{'id': '154', 'type': 'block', 'children': ['155', '186', '212']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '158', 'type': 'tuple', 'children': ['159', '168', '177']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '164', 'type': 'slice', 'children': ['165', '166', '167']},{'id': '165', 'type': 'integer', 'children': [], 'value': '30'},{'id': '166', 'type': 'colon', 'children': []},{'id': '167', 'type': 'integer', 'children': [], 'value': '38'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '173', 'type': 'slice', 'children': ['174', '175', '176']},{'id': '174', 'type': 'integer', 'children': [], 'value': '38'},{'id': '175', 'type': 'colon', 'children': []},{'id': '176', 'type': 'integer', 'children': [], 'value': '46'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '182', 'type': 'slice', 'children': ['183', '184', '185']},{'id': '183', 'type': 'integer', 'children': [], 'value': '46'},{'id': '184', 'type': 'colon', 'children': []},{'id': '185', 'type': 'integer', 'children': [], 'value': '54'},{'id': '186', 'type': 'for_statement', 'children': ['187', '188', '195']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'shash'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'nearby'},{'id': '192', 'type': 'argument_list', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'if_statement', 'children': ['197', '202']},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '201'], 'value': 'not'},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '200', 'type': 'integer', 'children': [], 'value': '1'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'neighbor_list'},{'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': 'neighbor_list'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '211', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'neighbor_list'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '217', 'type': 'argument_list', 'children': []},{'id': '218', 'type': 'return_statement', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'neighbor_list'}
def neighbors2(self, distance, chain_residue, atom = None, resid_list = None): '''this one is more precise since it uses the chain identifier also''' if atom == None: lines = [line for line in self.atomlines(resid_list) if line[17:20] in allowed_PDB_residues_types] else: lines = [line for line in self.atomlines(resid_list) if line[17:20] in allowed_PDB_residues_types and line[12:16] == atom] shash = spatialhash.SpatialHash(distance) for line in lines: pos = (float(line[30:38]), float(line[38:46]), float(line[46:54])) shash.insert(pos, line[21:26]) neighbor_list = [] for line in lines: resid = line[21:26] if resid == chain_residue: pos = (float(line[30:38]), float(line[38:46]), float(line[46:54])) for data in shash.nearby(pos, distance): if data[1] not in neighbor_list: neighbor_list.append(data[1]) neighbor_list.sort() return neighbor_list
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_document'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17', '20', '23']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'item_uri'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'docurl'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'displaydoc'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'preferName'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'contrib_id'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'block', 'children': ['27', '52', '70', '79', '88', '133', '186', '193', '211', '219']},{'id': '27', 'type': 'if_statement', 'children': ['28', '34', '46']},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '31'], 'value': 'and'},{'id': '29', 'type': 'not_operator', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'preferName'},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'file'},{'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': 'docid'},{'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': 'os'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'docid'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'docmeta'},{'id': '55', 'type': 'dictionary', 'children': ['56']},{'id': '56', 'type': 'pair', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': '"metadata"'},{'id': '58', 'type': 'dictionary', 'children': ['59', '64', '67']},{'id': '59', 'type': 'pair', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': '"@context"'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '64', 'type': 'pair', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': '"@type"'},{'id': '66', 'type': 'string', 'children': [], 'value': '"foaf:Document"'},{'id': '67', 'type': 'pair', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': '"dcterms:identifier"'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'docid'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'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': 'docmeta'},{'id': '75', 'type': 'string', 'children': [], 'value': '"metadata"'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '79', 'type': 'if_statement', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'contrib_id'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '87']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'docmeta'},{'id': '86', 'type': 'string', 'children': [], 'value': "'contribution_id'"},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'contrib_id'},{'id': '88', 'type': 'if_statement', 'children': ['89', '92', '99', '115', '126']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'is'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '91', 'type': 'None', 'children': []},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '98']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'docmeta'},{'id': '97', 'type': 'string', 'children': [], 'value': "'document_content'"},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '99', 'type': 'elif_clause', 'children': ['100', '103']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'docurl'},{'id': '102', 'type': 'None', 'children': []},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '111']},{'id': '106', 'type': 'subscript', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'docmeta'},{'id': '109', 'type': 'string', 'children': [], 'value': '"metadata"'},{'id': '110', 'type': 'string', 'children': [], 'value': '"dcterms:source"'},{'id': '111', 'type': 'dictionary', 'children': ['112']},{'id': '112', 'type': 'pair', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': '"@id"'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'docurl'},{'id': '115', 'type': 'elif_clause', 'children': ['116', '119']},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'is'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '118', 'type': 'None', 'children': []},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'docmeta'},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'docmeta'},{'id': '125', 'type': 'string', 'children': [], 'value': "'metadata'"},{'id': '126', 'type': 'else_clause', 'children': ['127']},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'raise_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': '"One of content, docurl or file must be specified in add_document"'},{'id': '133', 'type': 'if_statement', 'children': ['134', '137', '164']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': 'is'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '136', 'type': 'None', 'children': []},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'result'},{'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': 'api_request'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147', '150', '161']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'item_uri'},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '149', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '152', 'type': 'dictionary', 'children': ['153']},{'id': '153', 'type': 'pair', 'children': ['154', '155']},{'id': '154', 'type': 'string', 'children': [], 'value': "'metadata'"},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'docmeta'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '164', 'type': 'else_clause', 'children': ['165']},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'api_request'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175', '178']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'item_uri'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '177', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'docmeta'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '190', 'type': 'identifier', 'children': [], 'value': '__check_success'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '193', 'type': 'if_statement', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'displaydoc'},{'id': '195', 'type': 'block', 'children': ['196', '203']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'itemmeta'},{'id': '199', 'type': 'dictionary', 'children': ['200']},{'id': '200', 'type': 'pair', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': '"http://alveo.edu.org/vocabulary/display_document"'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'docid'},{'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': 'modify_item'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'item_uri'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'itemmeta'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'doc_uri'},{'id': '214', 'type': 'binary_operator', 'children': ['215', '218'], 'value': '+'},{'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '+'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'item_uri'},{'id': '217', 'type': 'string', 'children': [], 'value': '"/document/"'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '219', 'type': 'return_statement', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'doc_uri'}
def add_document(self, item_uri, name, metadata, content=None, docurl=None, file=None, displaydoc=False, preferName=False, contrib_id=None): if not preferName and file is not None: docid = os.path.basename(file) else: docid = name docmeta = {"metadata": {"@context": self.context, "@type": "foaf:Document", "dcterms:identifier": docid, } } docmeta["metadata"].update(metadata) if contrib_id: docmeta['contribution_id'] = contrib_id if content is not None: docmeta['document_content'] = content elif docurl is not None: docmeta["metadata"]["dcterms:source"] = { "@id": docurl } elif file is not None: docmeta = docmeta['metadata'] else: raise Exception("One of content, docurl or file must be specified in add_document") if file is not None: result = self.api_request(item_uri, method='POST', data={'metadata': json.dumps(docmeta)}, file=file) else: result = self.api_request(item_uri, method='POST', data=json.dumps(docmeta)) self.__check_success(result) if displaydoc: itemmeta = {"http://alveo.edu.org/vocabulary/display_document": docid} self.modify_item(item_uri, itemmeta) doc_uri = item_uri + "/document/" + name return doc_uri
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_agents'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'addr'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'agent_cls'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'include_manager'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '17', '32', '71', '91', '104']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'''Get agents in the environment.\n :param bool addr: If ``True``, returns only addresses of the agents.\n :param agent_cls:\n Optional, if specified returns only agents belonging to that\n particular class.\n :param bool include_manager:\n If `True``` includes the environment's manager, i.e. the agent in\n the address ``tcp://environment-host:port/0``, to the returned\n list if the environment has attribute :attr:`manager`. If\n environment does not have :attr:`manager`, then the parameter does\n nothing.\n :returns: A list of agents in the environment.\n :rtype: list\n .. note::\n By design, manager agents are excluded from the returned lists of\n agents by default.\n '''"},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '31']},{'id': '24', 'type': 'attribute', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'if_statement', 'children': ['33', '44']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '39'], 'value': 'and'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'string', 'children': [], 'value': "'manager'"},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': 'is'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'manager'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'if_statement', 'children': ['46', '48']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'include_manager'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '52', 'type': 'list_comprehension', 'children': ['53', '54', '57']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '57', 'type': 'if_clause', 'children': ['58']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '70'], 'value': '!='},{'id': '59', 'type': 'subscript', 'children': ['60', '69']},{'id': '60', 'type': 'call', 'children': ['61', '66']},{'id': '61', 'type': 'attribute', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'addr'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'string', 'children': [], 'value': "'0'"},{'id': '71', 'type': 'if_statement', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'agent_cls'},{'id': '74', 'type': 'None', 'children': []},{'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': 'agents'},{'id': '79', 'type': 'list_comprehension', 'children': ['80', '81', '84']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '81', 'type': 'for_in_clause', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '84', 'type': 'if_clause', 'children': ['85']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '90'], 'value': 'is'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'agent_cls'},{'id': '91', 'type': 'if_statement', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'addr'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '97', 'type': 'list_comprehension', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'addr'},{'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'agents'},{'id': '104', 'type': 'return_statement', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'agents'}
def get_agents(self, addr=True, agent_cls=None, include_manager=False): '''Get agents in the environment. :param bool addr: If ``True``, returns only addresses of the agents. :param agent_cls: Optional, if specified returns only agents belonging to that particular class. :param bool include_manager: If `True``` includes the environment's manager, i.e. the agent in the address ``tcp://environment-host:port/0``, to the returned list if the environment has attribute :attr:`manager`. If environment does not have :attr:`manager`, then the parameter does nothing. :returns: A list of agents in the environment. :rtype: list .. note:: By design, manager agents are excluded from the returned lists of agents by default. ''' agents = list(self.agents.dict.values()) if hasattr(self, 'manager') and self.manager is not None: if not include_manager: agents = [a for a in agents if a.addr.rsplit('/', 1)[1] != '0'] if agent_cls is not None: agents = [a for a in agents if type(a) is agent_cls] if addr: agents = [agent.addr for agent in agents] return agents
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tee'},{'id': '3', 'type': 'parameters', 'children': ['4', '6']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'popenargs'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '16', '38', '46', '73', '167', '181', '195']},{'id': '9', 'type': 'import_statement', 'children': ['10', '12', '14']},{'id': '10', 'type': 'dotted_name', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '14', 'type': 'dotted_name', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '23', 'type': 'argument_list', 'children': ['24', '29', '34', '36']},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '34', 'type': 'list_splat', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'popenargs'},{'id': '36', 'type': 'dictionary_splat', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '43']},{'id': '40', 'type': 'pattern_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '43', 'type': 'expression_list', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "''"},{'id': '45', 'type': 'string', 'children': [], 'value': "''"},{'id': '46', 'type': 'function_definition', 'children': ['47', '48', '51']},{'id': '47', 'type': 'function_name', 'children': [], 'value': 'read_stream'},{'id': '48', 'type': 'parameters', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'input_callback'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'output_stream'},{'id': '51', 'type': 'block', 'children': ['52', '58', '65', '71']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'input_callback'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'output_stream'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'output_stream'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '73', 'type': 'while_statement', 'children': ['74', '81']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '80'], 'value': 'is'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'None', 'children': []},{'id': '81', 'type': 'block', 'children': ['82', '100', '113']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'watch'},{'id': '85', 'type': 'expression_list', 'children': ['86', '93']},{'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': 'process'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'fileno'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'call', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'fileno'},{'id': '99', 'type': 'argument_list', 'children': []},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ready'},{'id': '103', 'type': 'subscript', 'children': ['104', '112']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110', '111']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'watch'},{'id': '110', 'type': 'list', 'children': [], 'value': '[]'},{'id': '111', 'type': 'list', 'children': [], 'value': '[]'},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'for_statement', 'children': ['114', '115', '116']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ready'},{'id': '116', 'type': 'block', 'children': ['117', '142']},{'id': '117', 'type': 'if_statement', 'children': ['118', '127']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '=='},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'fd'},{'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': 'process'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'fileno'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'augmented_assignment', 'children': ['130', '131'], 'value': '+='},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'read_stream'},{'id': '133', 'type': 'argument_list', 'children': ['134', '139']},{'id': '134', 'type': 'attribute', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '142', 'type': 'if_statement', 'children': ['143', '152']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': '=='},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'fd'},{'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': 'process'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'fileno'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'augmented_assignment', 'children': ['155', '156'], 'value': '+='},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'read_stream'},{'id': '158', 'type': 'argument_list', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'augmented_assignment', 'children': ['169', '170'], 'value': '+='},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'read_stream'},{'id': '172', 'type': 'argument_list', 'children': ['173', '178']},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'augmented_assignment', 'children': ['183', '184'], 'value': '+='},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'read_stream'},{'id': '186', 'type': 'argument_list', 'children': ['187', '192']},{'id': '187', 'type': 'attribute', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '195', 'type': 'return_statement', 'children': ['196']},{'id': '196', 'type': 'expression_list', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'stderr'}
def tee(*popenargs, **kwargs): import subprocess, select, sys process = subprocess.Popen( stdout=subprocess.PIPE, stderr=subprocess.PIPE, *popenargs, **kwargs) stdout, stderr = '', '' def read_stream(input_callback, output_stream): read = input_callback() output_stream.write(read) output_stream.flush() return read while process.poll() is None: watch = process.stdout.fileno(), process.stderr.fileno() ready = select.select(watch, [], [])[0] for fd in ready: if fd == process.stdout.fileno(): stdout += read_stream(process.stdout.readline, sys.stdout) if fd == process.stderr.fileno(): stderr += read_stream(process.stderr.readline, sys.stderr) stdout += read_stream(process.stdout.read, sys.stdout) stderr += read_stream(process.stderr.read, sys.stderr) return stdout, stderr
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dump_object'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '6', 'type': 'block', 'children': ['7', '21', '34', '56']},{'id': '7', 'type': 'if_statement', 'children': ['8', '15']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '10', 'type': 'argument_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'UUID'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '21', 'type': 'if_statement', 'children': ['22', '27']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '26', 'type': 'string', 'children': [], 'value': "'isoformat'"},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'isoformat'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'if_statement', 'children': ['35', '43']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '39', 'type': 'tuple', 'children': ['40', '41', '42']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'memoryview'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '54']},{'id': '46', 'type': 'attribute', 'children': ['47', '53']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'base64'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'b64encode'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'string', 'children': [], 'value': "'ASCII'"},{'id': '56', 'type': 'raise_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'{!r} is not JSON serializable'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'obj'}
def dump_object(self, obj): if isinstance(obj, uuid.UUID): return str(obj) if hasattr(obj, 'isoformat'): return obj.isoformat() if isinstance(obj, (bytes, bytearray, memoryview)): return base64.b64encode(obj).decode('ASCII') raise TypeError('{!r} is not JSON serializable'.format(obj))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'normalize_datum'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '6', 'type': 'block', 'children': ['7', '14', '25', '41', '55', '70', '85', '96', '120', '156']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'is'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '14', 'type': 'if_statement', 'children': ['15', '22']},{'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': 'datum'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'PACKABLE_TYPES'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '25', 'type': 'if_statement', 'children': ['26', '33']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'UUID'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '41', 'type': 'if_statement', 'children': ['42', '47']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '55', 'type': 'if_statement', 'children': ['56', '61']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'memoryview'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'tobytes'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'if_statement', 'children': ['71', '76']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '75', 'type': 'string', 'children': [], 'value': "'isoformat'"},{'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': 'datum'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'isoformat'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'if_statement', 'children': ['86', '93']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '90', 'type': 'tuple', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '96', 'type': 'if_statement', 'children': ['97', '108']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '101', 'type': 'tuple', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'Sequence'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'Set'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'list_comprehension', 'children': ['111', '117']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'normalize_datum'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '117', 'type': 'for_in_clause', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '120', 'type': 'if_statement', 'children': ['121', '128']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'Mapping'},{'id': '128', 'type': 'block', 'children': ['129', '133', '154']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '132', 'type': 'dictionary', 'children': []},{'id': '133', 'type': 'for_statement', 'children': ['134', '137', '142']},{'id': '134', 'type': 'pattern_list', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'k'},{'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': 'normalize_datum'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '154', 'type': 'return_statement', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '156', 'type': 'raise_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'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': "'{} is not msgpackable'"},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'attribute', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '168', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '__name__'}
def normalize_datum(self, datum): if datum is None: return datum if isinstance(datum, self.PACKABLE_TYPES): return datum if isinstance(datum, uuid.UUID): datum = str(datum) if isinstance(datum, bytearray): datum = bytes(datum) if isinstance(datum, memoryview): datum = datum.tobytes() if hasattr(datum, 'isoformat'): datum = datum.isoformat() if isinstance(datum, (bytes, str)): return datum if isinstance(datum, (collections.Sequence, collections.Set)): return [self.normalize_datum(item) for item in datum] if isinstance(datum, collections.Mapping): out = {} for k, v in datum.items(): out[k] = self.normalize_datum(v) return out raise TypeError( '{} is not msgpackable'.format(datum.__class__.__name__))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'redirect'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '7', 'type': 'block', 'children': ['8', '12', '128']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_endpoint'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'if_statement', 'children': ['13', '20', '73']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '20', 'type': 'block', 'children': ['21', '25']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_endpoint'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '25', 'type': 'if_statement', 'children': ['26', '29', '35']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'in'},{'id': '27', 'type': 'string', 'children': [], 'value': '"/"'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'f_redirect'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '35', 'type': 'else_clause', 'children': ['36']},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'for_statement', 'children': ['38', '39', '48']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '39', 'type': 'call', 'children': ['40', '47']},{'id': '40', 'type': 'attribute', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'Mocha'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_app'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'url_map'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'iter_rules'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'block', 'children': ['49', '53']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_endpoint'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '53', 'type': 'if_statement', 'children': ['54', '65']},{'id': '54', 'type': 'boolean_operator', 'children': ['55', '60'], 'value': 'and'},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'},{'id': '56', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'methods'},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '65', 'type': 'block', 'children': ['66', '72']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_endpoint'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '72', 'type': 'break_statement', 'children': []},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'id': '74', 'type': 'block', 'children': ['75', '104']},{'id': '75', 'type': 'if_statement', 'children': ['76', '81']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'Mocha'},{'id': '81', 'type': 'block', 'children': ['82', '96']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '85', 'type': 'attribute', 'children': ['86', '95']},{'id': '86', 'type': 'attribute', 'children': ['87', '94']},{'id': '87', 'type': 'attribute', 'children': ['88', '93']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '91', 'type': 'identifier', 'children': [], 'value': '_getframe'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'f_back'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'f_code'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'co_name'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '104', 'type': 'if_statement', 'children': ['105', '109']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'is_method'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '109', 'type': 'block', 'children': ['110', '117']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_endpoint'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': '_get_action_endpoint'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '117', 'type': 'if_statement', 'children': ['118', '120']},{'id': '118', 'type': 'not_operator', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': '_endpoint'},{'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': '_endpoint'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': '_build_endpoint_route_name'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '128', 'type': 'if_statement', 'children': ['129', '130', '141']},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_endpoint'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'return_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'f_redirect'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'url_for'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_endpoint'},{'id': '139', 'type': 'dictionary_splat', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '141', 'type': 'else_clause', 'children': ['142']},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'raise_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'MochaError'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'string', 'children': [], 'value': '"Invalid endpoint"'}
def redirect(endpoint, **kw): _endpoint = None if isinstance(endpoint, six.string_types): _endpoint = endpoint if "/" in endpoint: return f_redirect(endpoint) else: for r in Mocha._app.url_map.iter_rules(): _endpoint = endpoint if 'GET' in r.methods and endpoint in r.endpoint: _endpoint = r.endpoint break else: if isinstance(endpoint, Mocha): fn = sys._getframe().f_back.f_code.co_name endpoint = getattr(endpoint, fn) if is_method(endpoint): _endpoint = _get_action_endpoint(endpoint) if not _endpoint: _endpoint = _build_endpoint_route_name(endpoint) if _endpoint: return f_redirect(url_for(_endpoint, **kw)) else: raise exceptions.MochaError("Invalid endpoint")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'search_term'},{'id': '7', 'type': 'block', 'children': ['8', '16', '24', '33', '80', '329']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'criterias'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'mongoengine'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'rel_criterias'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'mongoengine'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Q'},{'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': 'terms'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'shlex'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'search_term'},{'id': '33', 'type': 'if_statement', 'children': ['34', '50']},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '41'], 'value': 'and'},{'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': 'terms'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'RE_OBJECTID'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'block', 'children': ['51', '69']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'bson'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ObjectId'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '68', 'type': 'integer', 'children': [], 'value': '0'},{'id': '69', 'type': 'if_statement', 'children': ['70', '77']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '76'], 'value': '=='},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'return_statement', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '80', 'type': 'for_statement', 'children': ['81', '82', '83']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '83', 'type': 'block', 'children': ['84', '93', '102', '110', '325']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '89']},{'id': '86', 'type': 'pattern_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'parse_like_term'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '93', 'type': 'if_statement', 'children': ['94', '97']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '=='},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '96', 'type': 'string', 'children': [], 'value': "'contains'"},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '101', 'type': 'string', 'children': [], 'value': "'icontains'"},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'criteria'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'mongoengine'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'for_statement', 'children': ['111', '112', '115']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': '_search_fields'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'if_statement', 'children': ['117', '126', '206', '296']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'mongoengine'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'ReferenceField'},{'id': '126', 'type': 'block', 'children': ['127', '133', '158', '174', '189']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'rel_model'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'document_type'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'rel_fields'},{'id': '136', 'type': '()', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '154']},{'id': '138', 'type': 'attribute', 'children': ['139', '153']},{'id': '139', 'type': 'call', 'children': ['140', '148']},{'id': '140', 'type': 'attribute', 'children': ['141', '147']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145', '146']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'string', 'children': [], 'value': "'column_searchable_refs'"},{'id': '146', 'type': 'dictionary', 'children': []},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '148', 'type': 'argument_list', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '152', 'type': 'dictionary', 'children': []},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '154', 'type': 'argument_list', 'children': ['155', '156']},{'id': '155', 'type': 'string', 'children': [], 'value': "'fields'"},{'id': '156', 'type': 'list', 'children': ['157'], 'value': "['id']"},{'id': '157', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '158', 'type': 'if_statement', 'children': ['159', '172']},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '164'], 'value': 'and'},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': '=='},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'rel_fields'},{'id': '162', 'type': 'list', 'children': ['163'], 'value': "['id']"},{'id': '163', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '164', 'type': 'not_operator', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'RE_OBJECTID'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'continue_statement', 'children': []},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '177', 'type': 'list_comprehension', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '181', 'type': 'for_in_clause', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'search_relative_field'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187', '188']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'rel_model'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'rel_fields'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'augmented_assignment', 'children': ['191', '192'], 'value': '|='},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'rel_criterias'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'mongoengine'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'dictionary_splat', 'children': ['198']},{'id': '198', 'type': 'dictionary', 'children': ['199']},{'id': '199', 'type': 'pair', 'children': ['200', '205']},{'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '%'},{'id': '201', 'type': 'string', 'children': [], 'value': "'%s__in'"},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '206', 'type': 'elif_clause', 'children': ['207', '216']},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'mongoengine'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'ListField'},{'id': '216', 'type': 'block', 'children': ['217', '232', '240', '264', '279']},{'id': '217', 'type': 'if_statement', 'children': ['218', '230']},{'id': '218', 'type': 'not_operator', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '221', 'type': 'argument_list', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '225', 'type': 'attribute', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'mongoengine'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'ReferenceField'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'continue_statement', 'children': []},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'rel_model'},{'id': '235', 'type': 'attribute', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'document_type_obj'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'rel_fields'},{'id': '243', 'type': '()', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '261']},{'id': '245', 'type': 'attribute', 'children': ['246', '260']},{'id': '246', 'type': 'call', 'children': ['247', '255']},{'id': '247', 'type': 'attribute', 'children': ['248', '254']},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '250', 'type': 'argument_list', 'children': ['251', '252', '253']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '252', 'type': 'string', 'children': [], 'value': "'column_searchable_refs'"},{'id': '253', 'type': 'dictionary', 'children': []},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '255', 'type': 'argument_list', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '259', 'type': 'dictionary', 'children': []},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': "'fields'"},{'id': '263', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '267', 'type': 'list_comprehension', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '271', 'type': 'for_in_clause', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'search_relative_field'},{'id': '275', 'type': 'argument_list', 'children': ['276', '277', '278']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'rel_model'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'rel_fields'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'augmented_assignment', 'children': ['281', '282'], 'value': '|='},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'rel_criterias'},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'mongoengine'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'dictionary_splat', 'children': ['288']},{'id': '288', 'type': 'dictionary', 'children': ['289']},{'id': '289', 'type': 'pair', 'children': ['290', '295']},{'id': '290', 'type': 'binary_operator', 'children': ['291', '292'], 'value': '%'},{'id': '291', 'type': 'string', 'children': [], 'value': "'%s__in'"},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '296', 'type': 'else_clause', 'children': ['297']},{'id': '297', 'type': 'block', 'children': ['298', '311', '321']},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'flt'},{'id': '301', 'type': 'dictionary', 'children': ['302']},{'id': '302', 'type': 'pair', 'children': ['303', '310']},{'id': '303', 'type': 'binary_operator', 'children': ['304', '305'], 'value': '%'},{'id': '304', 'type': 'string', 'children': [], 'value': "'%s__%s'"},{'id': '305', 'type': 'tuple', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'assignment', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'mongoengine'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'dictionary_splat', 'children': ['320']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'flt'},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'augmented_assignment', 'children': ['323', '324'], 'value': '|='},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'criteria'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'augmented_assignment', 'children': ['327', '328'], 'value': '&='},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'criterias'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'criteria'},{'id': '329', 'type': 'return_statement', 'children': ['330']},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '334', 'type': 'argument_list', 'children': ['335']},{'id': '335', 'type': 'binary_operator', 'children': ['336', '337'], 'value': '|'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'criterias'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'rel_criterias'}
def _search(self, query, search_term): criterias = mongoengine.Q() rel_criterias = mongoengine.Q() terms = shlex.split(search_term) if len(terms) == 1 and re.match(RE_OBJECTID, terms[0]): q = query.filter(id=bson.ObjectId(terms[0])) if q.count() == 1: return q for term in terms: op, term = parse_like_term(term) if op == 'contains': op = 'icontains' criteria = mongoengine.Q() for field in self._search_fields: if isinstance(field, mongoengine.fields.ReferenceField): rel_model = field.document_type rel_fields = ( getattr(self, 'column_searchable_refs', {}) .get(field.name, {}) .get('fields', ['id']) ) if rel_fields == ['id'] and not re.match(RE_OBJECTID, term): continue ids = [ o.id for o in search_relative_field(rel_model, rel_fields, term) ] rel_criterias |= mongoengine.Q(**{'%s__in' % field.name: ids}) elif isinstance(field, mongoengine.fields.ListField): if not isinstance(field.field, mongoengine.fields.ReferenceField): continue rel_model = field.field.document_type_obj rel_fields = ( getattr(self, 'column_searchable_refs', {}) .get(field.name, {}) .get('fields', 'id') ) ids = [ o.id for o in search_relative_field(rel_model, rel_fields, term) ] rel_criterias |= mongoengine.Q(**{'%s__in' % field.name: ids}) else: flt = {'%s__%s' % (field.name, op): term} q = mongoengine.Q(**flt) criteria |= q criterias &= criteria return query.filter(criterias | rel_criterias)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'replace_seqres'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'update_atoms'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '16', '20', '42', '46', '143', '261', '275']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'newpdb'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'PDB'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'inserted_seqres'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'entries_before_seqres'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'list', 'children': ['27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41'], 'value': '["HEADER", "OBSLTE", "TITLE", "CAVEAT", "COMPND", "SOURCE", \n "KEYWDS", "EXPDTA", "AUTHOR", "REVDAT", "SPRSDE", "JRNL", \n "REMARK", "DBREF", "SEQADV"]'},{'id': '27', 'type': 'string', 'children': [], 'value': '"HEADER"'},{'id': '28', 'type': 'string', 'children': [], 'value': '"OBSLTE"'},{'id': '29', 'type': 'string', 'children': [], 'value': '"TITLE"'},{'id': '30', 'type': 'string', 'children': [], 'value': '"CAVEAT"'},{'id': '31', 'type': 'string', 'children': [], 'value': '"COMPND"'},{'id': '32', 'type': 'string', 'children': [], 'value': '"SOURCE"'},{'id': '33', 'type': 'string', 'children': [], 'value': '"KEYWDS"'},{'id': '34', 'type': 'string', 'children': [], 'value': '"EXPDTA"'},{'id': '35', 'type': 'string', 'children': [], 'value': '"AUTHOR"'},{'id': '36', 'type': 'string', 'children': [], 'value': '"REVDAT"'},{'id': '37', 'type': 'string', 'children': [], 'value': '"SPRSDE"'},{'id': '38', 'type': 'string', 'children': [], 'value': '"JRNL"'},{'id': '39', 'type': 'string', 'children': [], 'value': '"REMARK"'},{'id': '40', 'type': 'string', 'children': [], 'value': '"DBREF"'},{'id': '41', 'type': 'string', 'children': [], 'value': '"SEQADV"'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mutated_resids'},{'id': '45', 'type': 'dictionary', 'children': []},{'id': '46', 'type': 'if_statement', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'update_atoms'},{'id': '48', 'type': 'block', 'children': ['49', '55', '64', '76']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'old_seqs'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ChainSequences'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'chainresnums'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'old_seqs'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'parse_atoms'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '64', 'type': 'assert_statement', 'children': ['65']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '71'], 'value': '=='},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'old_seqs'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'for_statement', 'children': ['77', '78', '83']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'block', 'children': ['84', '98']},{'id': '84', 'type': 'assert_statement', 'children': ['85']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '92'], 'value': '=='},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'old_seqs'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '98', 'type': 'for_statement', 'children': ['99', '100', '109']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'if_statement', 'children': ['111', '122']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '117'], 'value': '!='},{'id': '112', 'type': 'subscript', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '117', 'type': 'subscript', 'children': ['118', '121']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'old_seqs'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '122', 'type': 'block', 'children': ['123', '133']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '128', 'type': 'subscript', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'chainresnums'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'i'},{'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': 'mutated_resids'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '138', 'type': 'subscript', 'children': ['139', '142']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '143', 'type': 'for_statement', 'children': ['144', '145', '148']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '148', 'type': 'block', 'children': ['149', '158', '181']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '154', 'type': 'slice', 'children': ['155', '156', '157']},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'id': '156', 'type': 'colon', 'children': []},{'id': '157', 'type': 'integer', 'children': [], 'value': '6'},{'id': '158', 'type': 'if_statement', 'children': ['159', '166']},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '163'], 'value': 'and'},{'id': '160', 'type': '()', 'children': ['161']},{'id': '161', 'type': 'not_operator', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'inserted_seqres'},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': 'not'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'entries_before_seqres'},{'id': '166', 'type': 'block', 'children': ['167', '171']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'inserted_seqres'},{'id': '170', 'type': 'True', 'children': []},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'augmented_assignment', 'children': ['173', '176'], 'value': '+='},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'newpdb'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'seqres_lines'},{'id': '180', 'type': 'argument_list', 'children': []},{'id': '181', 'type': 'if_statement', 'children': ['182', '187', '249']},{'id': '182', 'type': 'boolean_operator', 'children': ['183', '184'], 'value': 'and'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'update_atoms'},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': '=='},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '186', 'type': 'string', 'children': [], 'value': '"ATOM "'},{'id': '187', 'type': 'block', 'children': ['188', '197', '210']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '193', 'type': 'slice', 'children': ['194', '195', '196']},{'id': '194', 'type': 'integer', 'children': [], 'value': '21'},{'id': '195', 'type': 'colon', 'children': []},{'id': '196', 'type': 'integer', 'children': [], 'value': '27'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '200', 'type': 'call', 'children': ['201', '209']},{'id': '201', 'type': 'attribute', 'children': ['202', '208']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '204', 'type': 'slice', 'children': ['205', '206', '207']},{'id': '205', 'type': 'integer', 'children': [], 'value': '12'},{'id': '206', 'type': 'colon', 'children': []},{'id': '207', 'type': 'integer', 'children': [], 'value': '16'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'if_statement', 'children': ['211', '218', '226']},{'id': '211', 'type': 'not_operator', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'mutated_resids'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'has_key'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'augmented_assignment', 'children': ['221', '224'], 'value': '+='},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'newpdb'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '224', 'type': 'list', 'children': ['225'], 'value': '[line]'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '226', 'type': 'else_clause', 'children': ['227']},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'augmented_assignment', 'children': ['230', '233'], 'value': '+='},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'newpdb'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '233', 'type': 'list', 'children': ['234'], 'value': '[line[:17] + mutated_resids[resid] + line[20:]]'},{'id': '234', 'type': 'binary_operator', 'children': ['235', '244'], 'value': '+'},{'id': '235', 'type': 'binary_operator', 'children': ['236', '241'], 'value': '+'},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '238', 'type': 'slice', 'children': ['239', '240']},{'id': '239', 'type': 'colon', 'children': []},{'id': '240', 'type': 'integer', 'children': [], 'value': '17'},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'mutated_resids'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'resid'},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '246', 'type': 'slice', 'children': ['247', '248']},{'id': '247', 'type': 'integer', 'children': [], 'value': '20'},{'id': '248', 'type': 'colon', 'children': []},{'id': '249', 'type': 'elif_clause', 'children': ['250', '253']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': '!='},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '252', 'type': 'string', 'children': [], 'value': '"SEQRES"'},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'augmented_assignment', 'children': ['256', '259'], 'value': '+='},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'newpdb'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '259', 'type': 'list', 'children': ['260'], 'value': '[line]'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '261', 'type': 'if_statement', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'update_atoms'},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'newpdb'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'remove_nonbackbone_atoms'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'mutated_resids'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '274', 'type': 'argument_list', 'children': []},{'id': '275', 'type': 'return_statement', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'newpdb'}
def replace_seqres(self, pdb, update_atoms = True): newpdb = PDB() inserted_seqres = False entries_before_seqres = set(["HEADER", "OBSLTE", "TITLE", "CAVEAT", "COMPND", "SOURCE", "KEYWDS", "EXPDTA", "AUTHOR", "REVDAT", "SPRSDE", "JRNL", "REMARK", "DBREF", "SEQADV"]) mutated_resids = {} if update_atoms: old_seqs = ChainSequences() chainresnums = old_seqs.parse_atoms(pdb) assert self.keys() == old_seqs.keys() for chain in self.keys(): assert len(self[chain]) == len(old_seqs[chain]) for i in xrange(len(self[chain])): if self[chain][i] != old_seqs[chain][i]: resid = chain + chainresnums[chain][i] mutated_resids[resid] = self[chain][i] for line in pdb.lines: entry = line[0:6] if (not inserted_seqres) and entry not in entries_before_seqres: inserted_seqres = True newpdb.lines += self.seqres_lines() if update_atoms and entry == "ATOM ": resid = line[21:27] atom = line[12:16].strip() if not mutated_resids.has_key(resid): newpdb.lines += [line] else: newpdb.lines += [line[:17] + mutated_resids[resid] + line[20:]] elif entry != "SEQRES": newpdb.lines += [line] if update_atoms: newpdb.remove_nonbackbone_atoms(mutated_resids.keys()) return newpdb
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'enrich_json_objects_by_object_type'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '6', 'type': 'block', 'children': ['7', '13', '62', '74', '212', '228']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'time_start_globally'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'if_statement', 'children': ['14', '19', '39']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '23', 'type': 'list_comprehension', 'children': ['24', '36']},{'id': '24', 'type': 'conditional_expression', 'children': ['25', '30', '35'], 'value': 'if'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'to_json'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '34', 'type': 'string', 'children': [], 'value': '"to_json"'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '39', 'type': 'else_clause', 'children': ['40']},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'if_statement', 'children': ['42', '47', '52']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'value'},{'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': 'json'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'to_json'},{'id': '61', 'type': 'argument_list', 'children': []},{'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': 'objects'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'nested'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_collect_json_objects'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '73', 'type': 'string', 'children': [], 'value': "'object_type'"},{'id': '74', 'type': 'for_statement', 'children': ['75', '76', '79']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'enricher_info'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_get_OBJECT_TYPE_ENRICHER_ORDER'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'block', 'children': ['80', '152']},{'id': '80', 'type': 'if_statement', 'children': ['81', '89', '128']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '88'], 'value': '>'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'enricher_info'},{'id': '87', 'type': 'string', 'children': [], 'value': "'object_types'"},{'id': '88', 'type': 'integer', 'children': [], 'value': '0'},{'id': '89', 'type': 'block', 'children': ['90', '109']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'enricher_objects'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'list_comprehension', 'children': ['97', '104']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'object_type'},{'id': '103', 'type': 'list', 'children': [], 'value': '[]'},{'id': '104', 'type': 'for_in_clause', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'object_type'},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'enricher_info'},{'id': '108', 'type': 'string', 'children': [], 'value': "'object_types'"},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'enricher_nested'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'list_comprehension', 'children': ['116', '123']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'nested'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'object_type'},{'id': '122', 'type': 'False', 'children': []},{'id': '123', 'type': 'for_in_clause', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'object_type'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'enricher_info'},{'id': '127', 'type': 'string', 'children': [], 'value': "'object_types'"},{'id': '128', 'type': 'else_clause', 'children': ['129']},{'id': '129', 'type': 'block', 'children': ['130', '141']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'enricher_objects'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '140', 'type': 'argument_list', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'enricher_nested'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'nested'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'if_statement', 'children': ['153', '159']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '158'], 'value': '>'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'enricher_objects'},{'id': '158', 'type': 'integer', 'children': [], 'value': '0'},{'id': '159', 'type': 'block', 'children': ['160', '166', '175', '194']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'time_start'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'enricher_info'},{'id': '170', 'type': 'string', 'children': [], 'value': "'enricher'"},{'id': '171', 'type': 'argument_list', 'children': ['172', '173', '174']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'enricher_objects'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'enricher_nested'},{'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': 'LOGGER'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'string', 'children': [], 'value': '\'enrichment "{}" took {} seconds\''},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '185', 'type': 'argument_list', 'children': ['186', '189']},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'enricher_info'},{'id': '188', 'type': 'string', 'children': [], 'value': "'enricher_name'"},{'id': '189', 'type': 'binary_operator', 'children': ['190', '193'], 'value': '-'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'time_start'},{'id': '194', 'type': 'if_statement', 'children': ['195', '199']},{'id': '195', 'type': 'not_operator', 'children': ['196']},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'enricher_info'},{'id': '198', 'type': 'string', 'children': [], 'value': "'pure'"},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '205']},{'id': '202', 'type': 'pattern_list', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'nested'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': '_collect_json_objects'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '211', 'type': 'string', 'children': [], 'value': "'object_type'"},{'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': 'LOGGER'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': "'The whole enrichment of json objects by their object_type took {} seconds.'"},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'binary_operator', 'children': ['224', '227'], 'value': '-'},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '226', 'type': 'argument_list', 'children': []},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'time_start_globally'},{'id': '228', 'type': 'return_statement', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'json'}
def enrich_json_objects_by_object_type(request, value): time_start_globally = time() if isinstance(value, list): json = [x.to_json() if hasattr(x, "to_json") else x for x in value] else: if isinstance(value, dict): json = value else: json = value.to_json() objects, nested = _collect_json_objects(json, by='object_type') for enricher_info in _get_OBJECT_TYPE_ENRICHER_ORDER(): if len(enricher_info['object_types']) > 0: enricher_objects = flatten([objects.get(object_type, []) for object_type in enricher_info['object_types']]) enricher_nested = any([nested.get(object_type, False) for object_type in enricher_info['object_types']]) else: enricher_objects = flatten(objects.values()) enricher_nested = any(nested.values()) if len(enricher_objects) > 0: time_start = time() enricher_info['enricher'](request, enricher_objects, enricher_nested) LOGGER.debug('enrichment "{}" took {} seconds'.format(enricher_info['enricher_name'], time() - time_start)) if not enricher_info['pure']: objects, nested = _collect_json_objects(json, by='object_type') LOGGER.debug('The whole enrichment of json objects by their object_type took {} seconds.'.format(time() - time_start_globally)) return json
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'change_parent'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sender'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '17', '131', '258']},{'id': '9', 'type': 'if_statement', 'children': ['10', '15']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': 'is'},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': []},{'id': '17', 'type': 'if_statement', 'children': ['18', '33']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '32'], 'value': '!='},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'binary_operator', 'children': ['23', '26'], 'value': '&'},{'id': '23', 'type': 'set', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'term'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'term_id'"},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'changed_fields'},{'id': '32', 'type': 'integer', 'children': [], 'value': '0'},{'id': '33', 'type': 'block', 'children': ['34', '40', '57', '63', '110']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '43', 'type': 'conditional_expression', 'children': ['44', '49', '52'], 'value': 'if'},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '47', 'type': 'string', 'children': [], 'value': "'term'"},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'},{'id': '50', 'type': 'string', 'children': [], 'value': "'term'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '52', 'type': 'subscript', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '55', 'type': 'string', 'children': [], 'value': "'term_id'"},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '63', 'type': 'if_statement', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'is'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'block', 'children': ['68', '92']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '71', 'type': 'conditional_expression', 'children': ['72', '75', '80'], 'value': 'if'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'Term'},{'id': '80', 'type': 'attribute', 'children': ['81', '91']},{'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': 'Term'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '109']},{'id': '94', 'type': 'attribute', 'children': ['95', '108']},{'id': '95', 'type': 'call', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'ItemRelation'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '101', 'type': 'argument_list', 'children': ['102', '105']},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '117']},{'id': '112', 'type': 'attribute', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ItemRelation'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'get_or_create'},{'id': '117', 'type': 'argument_list', 'children': ['118', '125', '128']},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'visible'},{'id': '130', 'type': 'True', 'children': []},{'id': '131', 'type': 'if_statement', 'children': ['132', '147']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '146'], 'value': '!='},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'binary_operator', 'children': ['137', '140'], 'value': '&'},{'id': '137', 'type': 'set', 'children': ['138', '139']},{'id': '138', 'type': 'string', 'children': [], 'value': "'term_secondary'"},{'id': '139', 'type': 'string', 'children': [], 'value': "'term_secondary_id'"},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'changed_fields'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'block', 'children': ['148', '154', '160', '177', '224']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '163', 'type': 'conditional_expression', 'children': ['164', '169', '172'], 'value': 'if'},{'id': '164', 'type': 'subscript', 'children': ['165', '168']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '167', 'type': 'string', 'children': [], 'value': "'term_secondary'"},{'id': '168', 'type': 'integer', 'children': [], 'value': '0'},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': 'in'},{'id': '170', 'type': 'string', 'children': [], 'value': "'term_secondary'"},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'subscript', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '175', 'type': 'string', 'children': [], 'value': "'term_secondary_id'"},{'id': '176', 'type': 'integer', 'children': [], 'value': '0'},{'id': '177', 'type': 'if_statement', 'children': ['178', '181']},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': 'is'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '180', 'type': 'None', 'children': []},{'id': '181', 'type': 'block', 'children': ['182', '206']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '185', 'type': 'conditional_expression', 'children': ['186', '189', '194'], 'value': 'if'},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'Term'},{'id': '194', 'type': 'attribute', 'children': ['195', '205']},{'id': '195', 'type': 'call', 'children': ['196', '201']},{'id': '196', 'type': 'attribute', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'Term'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '223']},{'id': '208', 'type': 'attribute', 'children': ['209', '222']},{'id': '209', 'type': 'call', 'children': ['210', '215']},{'id': '210', 'type': 'attribute', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'ItemRelation'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '215', 'type': 'argument_list', 'children': ['216', '219']},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '223', 'type': 'argument_list', 'children': []},{'id': '224', 'type': 'if_statement', 'children': ['225', '236']},{'id': '225', 'type': 'boolean_operator', 'children': ['226', '231'], 'value': 'or'},{'id': '226', 'type': 'comparison_operator', 'children': ['227', '230'], 'value': 'is'},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'term_secondary'},{'id': '230', 'type': 'None', 'children': []},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '235'], 'value': 'is'},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'term_secondary_id'},{'id': '235', 'type': 'None', 'children': []},{'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': 'ItemRelation'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'get_or_create'},{'id': '244', 'type': 'argument_list', 'children': ['245', '252', '255']},{'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'term_secondary'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'visible'},{'id': '257', 'type': 'True', 'children': []},{'id': '258', 'type': 'if_statement', 'children': ['259', '274']},{'id': '259', 'type': 'comparison_operator', 'children': ['260', '273'], 'value': '!='},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'binary_operator', 'children': ['264', '267'], 'value': '&'},{'id': '264', 'type': 'set', 'children': ['265', '266']},{'id': '265', 'type': 'string', 'children': [], 'value': "'context'"},{'id': '266', 'type': 'string', 'children': [], 'value': "'context_id'"},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'changed_fields'},{'id': '273', 'type': 'integer', 'children': [], 'value': '0'},{'id': '274', 'type': 'block', 'children': ['275', '281', '298', '304', '351']},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '284', 'type': 'conditional_expression', 'children': ['285', '290', '293'], 'value': 'if'},{'id': '285', 'type': 'subscript', 'children': ['286', '289']},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '288', 'type': 'string', 'children': [], 'value': "'context'"},{'id': '289', 'type': 'integer', 'children': [], 'value': '0'},{'id': '290', 'type': 'comparison_operator', 'children': ['291', '292'], 'value': 'in'},{'id': '291', 'type': 'string', 'children': [], 'value': "'context'"},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '293', 'type': 'subscript', 'children': ['294', '297']},{'id': '294', 'type': 'subscript', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '296', 'type': 'string', 'children': [], 'value': "'context_id'"},{'id': '297', 'type': 'integer', 'children': [], 'value': '0'},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '304', 'type': 'if_statement', 'children': ['305', '308']},{'id': '305', 'type': 'comparison_operator', 'children': ['306', '307'], 'value': 'is'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '307', 'type': 'None', 'children': []},{'id': '308', 'type': 'block', 'children': ['309', '333']},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'assignment', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '312', 'type': 'conditional_expression', 'children': ['313', '316', '321'], 'value': 'if'},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '316', 'type': 'call', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '318', 'type': 'argument_list', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'Context'},{'id': '321', 'type': 'attribute', 'children': ['322', '332']},{'id': '322', 'type': 'call', 'children': ['323', '328']},{'id': '323', 'type': 'attribute', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'Context'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'keyword_argument', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '350']},{'id': '335', 'type': 'attribute', 'children': ['336', '349']},{'id': '336', 'type': 'call', 'children': ['337', '342']},{'id': '337', 'type': 'attribute', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'ItemRelation'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '342', 'type': 'argument_list', 'children': ['343', '346']},{'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '346', 'type': 'keyword_argument', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '350', 'type': 'argument_list', 'children': []},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'call', 'children': ['353', '358']},{'id': '353', 'type': 'attribute', 'children': ['354', '357']},{'id': '354', 'type': 'attribute', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'ItemRelation'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'get_or_create'},{'id': '358', 'type': 'argument_list', 'children': ['359', '366', '369']},{'id': '359', 'type': 'keyword_argument', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '361', 'type': 'attribute', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'item_id'},{'id': '366', 'type': 'keyword_argument', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'child_id'},{'id': '369', 'type': 'keyword_argument', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'visible'},{'id': '371', 'type': 'True', 'children': []}
def change_parent(sender, instance, **kwargs): if instance.id is None: return if len({'term', 'term_id'} & set(instance.changed_fields)) != 0: diff = instance.diff parent = diff['term'][0] if 'term' in diff else diff['term_id'][0] child_id = instance.item_id if parent is not None: parent_id = parent.item_id if isinstance(parent, Term) else Term.objects.get(pk=parent).item_id ItemRelation.objects.filter(parent_id=parent_id, child_id=child_id).delete() ItemRelation.objects.get_or_create(parent_id=instance.term.item_id, child_id=child_id, visible=True) if len({'term_secondary', 'term_secondary_id'} & set(instance.changed_fields)) != 0: diff = instance.diff child_id = instance.item_id parent = diff['term_secondary'][0] if 'term_secondary' in diff else diff['term_secondary_id'][0] if parent is not None: parent_id = parent.item_id if isinstance(parent, Term) else Term.objects.get(pk=parent).item_id ItemRelation.objects.filter(parent_id=parent_id, child_id=child_id).delete() if instance.term_secondary is not None or instance.term_secondary_id is not None: ItemRelation.objects.get_or_create(parent_id=instance.term_secondary.item_id, child_id=child_id, visible=True) if len({'context', 'context_id'} & set(instance.changed_fields)) != 0: diff = instance.diff parent = diff['context'][0] if 'context' in diff else diff['context_id'][0] child_id = instance.item_id if parent is not None: parent_id = parent.item_id if isinstance(parent, Context) else Context.objects.get(pk=parent).item_id ItemRelation.objects.filter(parent_id=parent_id, child_id=child_id).delete() ItemRelation.objects.get_or_create(parent_id=instance.context.item_id, child_id=child_id, visible=True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'bin_atoms'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '26', '44', '60', '90', '94', '162', '231', '299', '303', '359']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''This function bins the Atoms into fixed-size sections of the protein space in 3D.'''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'low_point'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'list', 'children': ['17', '20', '23'], 'value': '[self.min_x, self.min_y, self.min_z]'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'min_x'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'min_y'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'min_z'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'high_point'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'list', 'children': ['35', '38', '41'], 'value': '[self.max_x, self.max_y, self.max_z]'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'max_x'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'max_y'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'max_z'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'binary_operator', 'children': ['53', '57'], 'value': '/'},{'id': '53', 'type': '()', 'children': ['54']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '-'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'high_point'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'low_point'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'bin_size'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '65', 'type': 'tuple', 'children': ['66', '74', '82']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '73'], 'value': '-'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '81'], 'value': '-'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '80', 'type': 'integer', 'children': [], 'value': '1'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'binary_operator', 'children': ['83', '89'], 'value': '-'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '88', 'type': 'integer', 'children': [], 'value': '2'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'atom_bins'},{'id': '93', 'type': 'list', 'children': [], 'value': '[]'},{'id': '94', 'type': 'for_statement', 'children': ['95', '96', '105']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'block', 'children': ['106', '113']},{'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': 'atom_bins'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'list', 'children': [], 'value': '[]'},{'id': '113', 'type': 'for_statement', 'children': ['114', '115', '124']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '123', 'type': 'integer', 'children': [], 'value': '1'},{'id': '124', 'type': 'block', 'children': ['125', '134']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '132']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'atom_bins'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'list', 'children': [], 'value': '[]'},{'id': '134', 'type': 'for_statement', 'children': ['135', '136', '145']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'z'},{'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': 'int'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '144', 'type': 'integer', 'children': [], 'value': '2'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '155']},{'id': '148', 'type': 'attribute', 'children': ['149', '154']},{'id': '149', 'type': 'subscript', 'children': ['150', '153']},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'atom_bins'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'Bin'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160', '161']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '162', 'type': 'for_statement', 'children': ['163', '166', '173']},{'id': '163', 'type': 'pattern_list', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'serial_number'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '166', 'type': 'call', 'children': ['167', '172']},{'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': 'atoms'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'block', 'children': ['174', '192', '217', '224']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'bin_location'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'trunc'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'binary_operator', 'children': ['183', '189'], 'value': '/'},{'id': '183', 'type': '()', 'children': ['184']},{'id': '184', 'type': 'binary_operator', 'children': ['185', '188'], 'value': '-'},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'point'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'low_point'},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'bin_size'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'bin'},{'id': '195', 'type': 'subscript', 'children': ['196', '211']},{'id': '196', 'type': 'subscript', 'children': ['197', '205']},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'atom_bins'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'bin_location'},{'id': '204', 'type': 'integer', 'children': [], 'value': '0'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'bin_location'},{'id': '210', 'type': 'integer', 'children': [], 'value': '1'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'bin_location'},{'id': '216', 'type': 'integer', 'children': [], 'value': '2'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'bin'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'atom'},{'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': 'atom'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'set_bin'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'bin'},{'id': '231', 'type': 'if_statement', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'safe_mode'},{'id': '235', 'type': 'block', 'children': ['236', '240', '289']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'num_atoms'},{'id': '239', 'type': 'integer', 'children': [], 'value': '0'},{'id': '240', 'type': 'for_statement', 'children': ['241', '242', '251']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'subscript', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '250', 'type': 'integer', 'children': [], 'value': '0'},{'id': '251', 'type': 'block', 'children': ['252']},{'id': '252', 'type': 'for_statement', 'children': ['253', '254', '263']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '262', 'type': 'integer', 'children': [], 'value': '1'},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'for_statement', 'children': ['265', '266', '275']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '274', 'type': 'integer', 'children': [], 'value': '2'},{'id': '275', 'type': 'block', 'children': ['276']},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'augmented_assignment', 'children': ['278', '279'], 'value': '+='},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'num_atoms'},{'id': '279', 'type': 'call', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'subscript', 'children': ['283', '288']},{'id': '283', 'type': 'subscript', 'children': ['284', '287']},{'id': '284', 'type': 'subscript', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'atom_bins'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '289', 'type': 'assert_statement', 'children': ['290']},{'id': '290', 'type': '()', 'children': ['291']},{'id': '291', 'type': 'comparison_operator', 'children': ['292', '293'], 'value': '=='},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'num_atoms'},{'id': '293', 'type': 'call', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'atoms'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'blank_section'},{'id': '302', 'type': 'tuple', 'children': []},{'id': '303', 'type': 'for_statement', 'children': ['304', '305', '314']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '305', 'type': 'call', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'subscript', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '313', 'type': 'integer', 'children': [], 'value': '0'},{'id': '314', 'type': 'block', 'children': ['315']},{'id': '315', 'type': 'for_statement', 'children': ['316', '317', '326']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '317', 'type': 'call', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '322', 'type': 'argument_list', 'children': ['323']},{'id': '323', 'type': 'subscript', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '325', 'type': 'integer', 'children': [], 'value': '1'},{'id': '326', 'type': 'block', 'children': ['327']},{'id': '327', 'type': 'for_statement', 'children': ['328', '329', '338']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '329', 'type': 'call', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '331', 'type': 'argument_list', 'children': ['332']},{'id': '332', 'type': 'call', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '334', 'type': 'argument_list', 'children': ['335']},{'id': '335', 'type': 'subscript', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'atom_bin_dimensions'},{'id': '337', 'type': 'integer', 'children': [], 'value': '2'},{'id': '338', 'type': 'block', 'children': ['339']},{'id': '339', 'type': 'if_statement', 'children': ['340', '348']},{'id': '340', 'type': 'not_operator', 'children': ['341']},{'id': '341', 'type': 'subscript', 'children': ['342', '347']},{'id': '342', 'type': 'subscript', 'children': ['343', '346']},{'id': '343', 'type': 'subscript', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'atom_bins'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '348', 'type': 'block', 'children': ['349']},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'assignment', 'children': ['351', '358']},{'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': 'atom_bins'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'blank_section'},{'id': '359', 'type': 'expression_statement', 'children': ['360']},{'id': '360', 'type': 'assignment', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'atom_bins'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'atom_bins'}
def bin_atoms(self): '''This function bins the Atoms into fixed-size sections of the protein space in 3D.''' low_point = numpy.array([self.min_x, self.min_y, self.min_z]) high_point = numpy.array([self.max_x, self.max_y, self.max_z]) atom_bin_dimensions = numpy.ceil((high_point - low_point) / self.bin_size) self.atom_bin_dimensions = (int(atom_bin_dimensions[0]) - 1, int(atom_bin_dimensions[1]) - 1, int(atom_bin_dimensions[2]) - 1) atom_bins = [] for x in range(int(atom_bin_dimensions[0])): atom_bins.append([]) for y in range(int(atom_bin_dimensions[1])): atom_bins[x].append([]) for z in range(int(atom_bin_dimensions[2])): atom_bins[x][y].append(Bin(x, y, z)) for serial_number, atom in self.atoms.iteritems(): bin_location = numpy.trunc((atom.point - low_point) / self.bin_size) bin = atom_bins[int(bin_location[0])][int(bin_location[1])][int(bin_location[2])] bin.append(atom) atom.set_bin(bin) if self.safe_mode: num_atoms = 0 for x in range(int(atom_bin_dimensions[0])): for y in range(int(atom_bin_dimensions[1])): for z in range(int(atom_bin_dimensions[2])): num_atoms += len(atom_bins[x][y][z]) assert(num_atoms == len(self.atoms)) blank_section = () for x in range(int(atom_bin_dimensions[0])): for y in range(int(atom_bin_dimensions[1])): for z in range(int(atom_bin_dimensions[2])): if not atom_bins[x][y][z]: atom_bins[x][y][z] = blank_section self.atom_bins = atom_bins
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '6', 'type': 'list_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '8', 'type': 'block', 'children': ['9', '24', '39', '43', '52', '109']},{'id': '9', 'type': 'if_statement', 'children': ['10', '18']},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'raise_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "'attr_name must be a str.'"},{'id': '24', 'type': 'if_statement', 'children': ['25', '28']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'in'},{'id': '26', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'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': 'attr_name'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '38', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'parent_attr'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'parent_attr'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '51', 'type': 'None', 'children': []},{'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55', '106']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '55', 'type': 'block', 'children': ['56', '76']},{'id': '56', 'type': 'if_statement', 'children': ['57', '65']},{'id': '57', 'type': 'not_operator', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'raise_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': "'each additional argument must be a string. {0} was not a string'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '76', 'type': 'if_statement', 'children': ['77', '82']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'parent_attr'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '82', 'type': 'block', 'children': ['83', '91']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'parent_attr'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'parent_attr'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '91', 'type': 'if_statement', 'children': ['92', '97']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'parent_attr'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'parent_attr'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '106', 'type': 'else_clause', 'children': ['107']},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'pass_statement', 'children': []},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'attr'}
def get(self, attr_name, *args): if not isinstance(attr_name, six.string_types): raise TypeError('attr_name must be a str.') if '-' in attr_name: attr_name = attr_name.replace('-', '_') parent_attr = self attr = getattr(parent_attr, attr_name, None) for arg in args: if not isinstance(arg, six.string_types): raise TypeError( 'each additional argument must be a string. {0} was not a string'.format(arg) ) if hasattr(parent_attr, arg): parent_attr = getattr(parent_attr, arg) if hasattr(parent_attr, attr_name): attr = getattr(parent_attr, attr_name) else: pass return attr
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_load_yml_config'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '6', 'type': 'block', 'children': ['7', '22']},{'id': '7', 'type': 'if_statement', 'children': ['8', '16']},{'id': '8', 'type': 'not_operator', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'raise_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': "'config_file must be a str.'"},{'id': '22', 'type': 'try_statement', 'children': ['23', '263']},{'id': '23', 'type': 'block', 'children': ['24', '55', '87', '126', '158', '190', '198', '206', '214', '222', '230', '241', '251']},{'id': '24', 'type': 'function_definition', 'children': ['25', '26', '29']},{'id': '25', 'type': 'function_name', 'children': [], 'value': 'construct_yaml_int'},{'id': '26', 'type': 'parameters', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '29', 'type': 'block', 'children': ['30', '40', '53']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'SafeConstructor'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'construct_yaml_int'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ConfigInt'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47', '50']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'start_mark'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'end_mark'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '55', 'type': 'function_definition', 'children': ['56', '57', '60']},{'id': '56', 'type': 'function_name', 'children': [], 'value': 'construct_yaml_float'},{'id': '57', 'type': 'parameters', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '60', 'type': 'block', 'children': ['61', '72', '85']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '65']},{'id': '63', 'type': 'pattern_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'SafeConstructor'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'construct_yaml_float'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'ConfigFloat'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79', '82']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'start_mark'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'end_mark'},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '87', 'type': 'function_definition', 'children': ['88', '89', '92']},{'id': '88', 'type': 'function_name', 'children': [], 'value': 'construct_yaml_str'},{'id': '89', 'type': 'parameters', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '92', 'type': 'block', 'children': ['93', '103', '111', '124']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'SafeConstructor'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'construct_scalar'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '103', 'type': 'assert_statement', 'children': ['104']},{'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': 'obj'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ConfigUnicode'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118', '121']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'start_mark'},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'end_mark'},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '126', 'type': 'function_definition', 'children': ['127', '128', '131']},{'id': '127', 'type': 'function_name', 'children': [], 'value': 'construct_yaml_mapping'},{'id': '128', 'type': 'parameters', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '131', 'type': 'block', 'children': ['132', '143', '156']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '136']},{'id': '134', 'type': 'pattern_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'SafeConstructor'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'construct_yaml_map'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'ConfigDict'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150', '153']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'start_mark'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'end_mark'},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '158', 'type': 'function_definition', 'children': ['159', '160', '163']},{'id': '159', 'type': 'function_name', 'children': [], 'value': 'construct_yaml_seq'},{'id': '160', 'type': 'parameters', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '163', 'type': 'block', 'children': ['164', '175', '188']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '168']},{'id': '166', 'type': 'pattern_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'SafeConstructor'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'construct_yaml_seq'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'ConfigSeq'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182', '185']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'start_mark'},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'end_mark'},{'id': '188', 'type': 'return_statement', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'SafeConstructor'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'add_constructor'},{'id': '195', 'type': 'argument_list', 'children': ['196', '197']},{'id': '196', 'type': 'string', 'children': [], 'value': "u'tag:yaml.org,2002:float'"},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'construct_yaml_float'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'SafeConstructor'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'add_constructor'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': "u'tag:yaml.org,2002:int'"},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'construct_yaml_int'},{'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': 'SafeConstructor'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'add_constructor'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'string', 'children': [], 'value': "u'tag:yaml.org,2002:map'"},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'construct_yaml_mapping'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'SafeConstructor'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'add_constructor'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': "u'tag:yaml.org,2002:seq'"},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'construct_yaml_seq'},{'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': 'SafeConstructor'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'add_constructor'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229']},{'id': '228', 'type': 'string', 'children': [], 'value': "u'tag:yaml.org,2002:str'"},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'construct_yaml_str'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '233', 'type': 'call', 'children': ['234', '240']},{'id': '234', 'type': 'attribute', 'children': ['235', '239']},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'SafeLoader'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'get_data'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'if_statement', 'children': ['242', '245']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': 'is'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '244', 'type': 'None', 'children': []},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'raise_statement', 'children': ['247']},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'string', 'children': [], 'value': "'The configuration file needs to have data in it.'"},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '255', 'type': 'identifier', 'children': [], 'value': '_data'},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'normalize_keys'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'snake_case'},{'id': '262', 'type': 'False', 'children': []},{'id': '263', 'type': 'except_clause', 'children': ['264', '268']},{'id': '264', 'type': 'as_pattern', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'YAMLError'},{'id': '266', 'type': 'as_pattern_target', 'children': ['267']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'if_statement', 'children': ['270', '275', '301']},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '272', 'type': 'argument_list', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '274', 'type': 'string', 'children': [], 'value': "'problem_mark'"},{'id': '275', 'type': 'block', 'children': ['276', '282']},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'mark'},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'problem_mark'},{'id': '282', 'type': 'raise_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'string', 'children': [], 'value': '"There is a syntax error in your freight-forwarder config file line: {0} column: {1}"'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '290', 'type': 'argument_list', 'children': ['291', '296']},{'id': '291', 'type': 'binary_operator', 'children': ['292', '295'], 'value': '+'},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'mark'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '295', 'type': 'integer', 'children': [], 'value': '1'},{'id': '296', 'type': 'binary_operator', 'children': ['297', '300'], 'value': '+'},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'mark'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '300', 'type': 'integer', 'children': [], 'value': '1'},{'id': '301', 'type': 'else_clause', 'children': ['302']},{'id': '302', 'type': 'block', 'children': ['303']},{'id': '303', 'type': 'raise_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'string', 'children': [], 'value': '"There is a syntax error in your freight-forwarder config."'}
def _load_yml_config(self, config_file): if not isinstance(config_file, six.string_types): raise TypeError('config_file must be a str.') try: def construct_yaml_int(self, node): obj = SafeConstructor.construct_yaml_int(self, node) data = ConfigInt( obj, node.start_mark, node.end_mark ) return data def construct_yaml_float(self, node): obj, = SafeConstructor.construct_yaml_float(self, node) data = ConfigFloat( obj, node.start_mark, node.end_mark ) return data def construct_yaml_str(self, node): obj = SafeConstructor.construct_scalar(self, node) assert isinstance(obj, six.string_types) data = ConfigUnicode( obj, node.start_mark, node.end_mark ) return data def construct_yaml_mapping(self, node): obj, = SafeConstructor.construct_yaml_map(self, node) data = ConfigDict( obj, node.start_mark, node.end_mark ) return data def construct_yaml_seq(self, node): obj, = SafeConstructor.construct_yaml_seq(self, node) data = ConfigSeq( obj, node.start_mark, node.end_mark ) return data SafeConstructor.add_constructor(u'tag:yaml.org,2002:float', construct_yaml_float) SafeConstructor.add_constructor(u'tag:yaml.org,2002:int', construct_yaml_int) SafeConstructor.add_constructor(u'tag:yaml.org,2002:map', construct_yaml_mapping) SafeConstructor.add_constructor(u'tag:yaml.org,2002:seq', construct_yaml_seq) SafeConstructor.add_constructor(u'tag:yaml.org,2002:str', construct_yaml_str) data = SafeLoader(config_file).get_data() if data is None: raise AttributeError('The configuration file needs to have data in it.') self._data = normalize_keys(data, snake_case=False) except YAMLError as e: if hasattr(e, 'problem_mark'): mark = e.problem_mark raise SyntaxError( "There is a syntax error in your freight-forwarder config file line: {0} column: {1}".format( mark.line + 1, mark.column + 1 ) ) else: raise SyntaxError("There is a syntax error in your freight-forwarder config.")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_create_attr'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'property_key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '8', 'type': 'block', 'children': ['9', '32', '53', '57', '70', '74', '159']},{'id': '9', 'type': 'if_statement', 'children': ['10', '18']},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'property_key'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'raise_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'string', 'children': [], 'value': '"property_key must be a string. type: {0} was passed."'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'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': 'property_key'},{'id': '32', 'type': 'if_statement', 'children': ['33', '39']},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'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': 'TypeError'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': '"ancestors must be an OrderedDict. type: {0} was passed."'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'previous_element'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'normalized_key'},{'id': '60', 'type': 'call', 'children': ['61', '67']},{'id': '61', 'type': 'attribute', 'children': ['62', '66']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'normalize_value'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'property_key'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '69', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'normalized_ancestor_key'},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'if_statement', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'for_statement', 'children': ['78', '81', '87']},{'id': '78', 'type': 'pattern_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ancestor_key'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ancestors_value'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '87', 'type': 'block', 'children': ['88', '101', '111', '151']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'normalized_ancestor_key'},{'id': '91', 'type': 'call', 'children': ['92', '98']},{'id': '92', 'type': 'attribute', 'children': ['93', '97']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'normalize_value'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ancestor_key'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '100', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '101', 'type': 'if_statement', 'children': ['102', '109']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '108'], 'value': '=='},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'normalized_ancestor_key'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'string', 'children': [], 'value': "'root'"},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'continue_statement', 'children': []},{'id': '111', 'type': 'if_statement', 'children': ['112', '118']},{'id': '112', 'type': 'not_operator', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'previous_element'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'normalized_ancestor_key'},{'id': '118', 'type': 'block', 'children': ['119', '132', '138', '144']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'config_attr'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ConfigDict'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126', '129']},{'id': '125', 'type': 'dictionary', 'children': []},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'ancestors_value'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'start_mark'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ancestors_value'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'end_mark'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'config_attr'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'normalized_ancestor_key'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'config_attr'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'ancestor_key'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149', '150']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'previous_element'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'normalized_ancestor_key'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'config_attr'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'previous_element'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'previous_element'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'normalized_ancestor_key'},{'id': '159', 'type': 'if_statement', 'children': ['160', '163', '165']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': '=='},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'normalized_key'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'normalized_ancestor_key'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'pass_statement', 'children': []},{'id': '165', 'type': 'else_clause', 'children': ['166']},{'id': '166', 'type': 'block', 'children': ['167', '186']},{'id': '167', 'type': 'if_statement', 'children': ['168', '173']},{'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': 'data'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'ConfigNode'},{'id': '173', 'type': 'block', 'children': ['174', '180']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'normalized_key'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'property_key'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '189', 'type': 'argument_list', 'children': ['190', '191', '192']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'previous_element'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'normalized_key'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'data'}
def _create_attr(self, property_key, data, ancestors): if not isinstance(property_key, six.string_types): raise TypeError("property_key must be a string. type: {0} was passed.".format(type(property_key))) if not isinstance(ancestors, OrderedDict): raise TypeError("ancestors must be an OrderedDict. type: {0} was passed.".format(type(ancestors))) previous_element = self normalized_key = normalize_value(property_key).replace('-', '_') normalized_ancestor_key = None if ancestors: for ancestor_key, ancestors_value in six.iteritems(ancestors): normalized_ancestor_key = normalize_value(ancestor_key).replace('-', '_') if normalized_ancestor_key.lower() == 'root': continue if not hasattr(previous_element, normalized_ancestor_key): config_attr = ConfigDict({}, ancestors_value.start_mark, ancestors_value.end_mark) config_attr.name = normalized_ancestor_key config_attr.alias = ancestor_key setattr( previous_element, normalized_ancestor_key, config_attr ) previous_element = getattr(previous_element, normalized_ancestor_key) if normalized_key == normalized_ancestor_key: pass else: if isinstance(data, ConfigNode): data.name = normalized_key data.alias = property_key setattr(previous_element, normalized_key, data)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_collect_unrecognized_values'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '8', 'type': 'block', 'children': ['9', '30', '51', '55', '184']},{'id': '9', 'type': 'if_statement', 'children': ['10', '16']},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'raise_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'string', 'children': [], 'value': '"ancestors must be an OrderedDict. type: {0} was passed."'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '30', 'type': 'if_statement', 'children': ['31', '37']},{'id': '31', 'type': 'not_operator', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'dict'},{'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': 'TypeError'},{'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': "'scheme must be a dict. type: {0} was passed'"},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'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': 'scheme'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'unrecognized_values'},{'id': '54', 'type': 'dictionary', 'children': []},{'id': '55', 'type': 'if_statement', 'children': ['56', '61', '181']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '61', 'type': 'block', 'children': ['62', '84', '107', '116']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'pruned_scheme'},{'id': '65', 'type': 'list_comprehension', 'children': ['66', '67', '74']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '67', 'type': 'for_in_clause', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'if_clause', 'children': ['75']},{'id': '75', 'type': 'boolean_operator', 'children': ['76', '79'], 'value': 'and'},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'not'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'RESERVED_SCHEME_KEYS'},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '83'], 'value': 'not'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'RESERVED_SCHEME_KEYS'},{'id': '84', 'type': 'for_statement', 'children': ['85', '88', '94']},{'id': '85', 'type': 'pattern_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '94', 'type': 'block', 'children': ['95', '101']},{'id': '95', 'type': 'if_statement', 'children': ['96', '99']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'in'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'pruned_scheme'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'continue_statement', 'children': []},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '106']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'unrecognized_values'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'validations'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'string', 'children': [], 'value': "'is'"},{'id': '116', 'type': 'if_statement', 'children': ['117', '122']},{'id': '117', 'type': 'boolean_operator', 'children': ['118', '119'], 'value': 'and'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'validations'},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': 'in'},{'id': '120', 'type': 'string', 'children': [], 'value': "'one_of'"},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'validations'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'for_statement', 'children': ['124', '125', '128']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'nested_scheme'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'validations'},{'id': '127', 'type': 'string', 'children': [], 'value': "'one_of'"},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'if_statement', 'children': ['130', '135']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'nested_scheme'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '135', 'type': 'block', 'children': ['136', '146', '168']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'updated_scheme'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_update_scheme'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'nested_scheme'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'pruned_scheme'},{'id': '149', 'type': 'list_comprehension', 'children': ['150', '151', '158']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '151', 'type': 'for_in_clause', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'updated_scheme'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'if_clause', 'children': ['159']},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '163'], 'value': 'and'},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': 'not'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'RESERVED_SCHEME_KEYS'},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '167'], 'value': 'not'},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '166', 'type': 'integer', 'children': [], 'value': '0'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'RESERVED_SCHEME_KEYS'},{'id': '168', 'type': 'for_statement', 'children': ['169', '170', '171']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'pruned_scheme'},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'if_statement', 'children': ['173', '176']},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': 'in'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'unrecognized_values'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'delete_statement', 'children': ['178']},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'unrecognized_values'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '181', 'type': 'else_clause', 'children': ['182']},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'pass_statement', 'children': []},{'id': '184', 'type': 'return_statement', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'unrecognized_values'}
def _collect_unrecognized_values(self, scheme, data, ancestors): if not isinstance(ancestors, OrderedDict): raise TypeError("ancestors must be an OrderedDict. type: {0} was passed.".format(type(ancestors))) if not isinstance(scheme, dict): raise TypeError('scheme must be a dict. type: {0} was passed'.format(type(scheme))) unrecognized_values = {} if isinstance(data, dict): pruned_scheme = [key for key in scheme.keys() if key not in RESERVED_SCHEME_KEYS and key[0] not in RESERVED_SCHEME_KEYS] for key, value in six.iteritems(data): if key in pruned_scheme: continue unrecognized_values[key] = value validations = scheme.get('is') if validations and 'one_of' in validations: for nested_scheme in validations['one_of']: if isinstance(nested_scheme, dict): updated_scheme = self._update_scheme(nested_scheme, ancestors) pruned_scheme = [key for key in updated_scheme.keys() if key not in RESERVED_SCHEME_KEYS and key[0] not in RESERVED_SCHEME_KEYS] for key in pruned_scheme: if key in unrecognized_values: del unrecognized_values[key] else: pass return unrecognized_values
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_update_scheme'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '7', 'type': 'block', 'children': ['8', '29', '50', '59', '74', '78', '221', '228']},{'id': '8', 'type': 'if_statement', 'children': ['9', '15']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'raise_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': '"ancestors must be an OrderedDict. type: {0} was passed."'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '29', 'type': 'if_statement', 'children': ['30', '36']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'raise_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': "'scheme must be a dict. type: {0} was passed'"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ROOT_SCHEME'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'},{'id': '61', 'type': 'string', 'children': [], 'value': "'inherit'"},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'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': 'scheme'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_scheme_propagation'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'updated_scheme'},{'id': '77', 'type': 'dictionary', 'children': []},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '86']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'scheme_key'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'iterkeys'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '86', 'type': 'block', 'children': ['87', '107']},{'id': '87', 'type': 'if_statement', 'children': ['88', '96']},{'id': '88', 'type': 'not_operator', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'scheme_key'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'raise_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': "'scheme keys are required to be strings. type: {0} was passed.'"},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'scheme_key'},{'id': '107', 'type': 'if_statement', 'children': ['108', '111', '169']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'in'},{'id': '109', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'scheme_key'},{'id': '111', 'type': 'block', 'children': ['112', '120', '131', '144']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'scheme_key'},{'id': '117', 'type': 'slice', 'children': ['118', '119']},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'colon', 'children': []},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'scheme_reference'},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_scheme_references'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '131', 'type': 'if_statement', 'children': ['132', '134']},{'id': '132', 'type': 'not_operator', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'scheme_reference'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'raise_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'ConfigValidationException'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140', '141', '142', '143']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'scheme_reference'},{'id': '142', 'type': 'string', 'children': [], 'value': "'required'"},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '144', 'type': 'for_statement', 'children': ['145', '146', '149']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'reference_key'},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'scheme_reference'},{'id': '148', 'type': 'string', 'children': [], 'value': "'keys'"},{'id': '149', 'type': 'block', 'children': ['150', '161']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '157']},{'id': '152', 'type': 'attribute', 'children': ['153', '156']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'scheme_reference'},{'id': '155', 'type': 'string', 'children': [], 'value': "'scheme'"},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'scheme_key'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '166']},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'updated_scheme'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'reference_key'},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'scheme_reference'},{'id': '168', 'type': 'string', 'children': [], 'value': "'scheme'"},{'id': '169', 'type': 'elif_clause', 'children': ['170', '173']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'in'},{'id': '171', 'type': 'string', 'children': [], 'value': "'~'"},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'scheme_key'},{'id': '173', 'type': 'block', 'children': ['174', '182', '193', '207']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'scheme_key'},{'id': '179', 'type': 'slice', 'children': ['180', '181']},{'id': '180', 'type': 'integer', 'children': [], 'value': '1'},{'id': '181', 'type': 'colon', 'children': []},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'scheme_reference'},{'id': '185', 'type': 'call', 'children': ['186', '191']},{'id': '186', 'type': 'attribute', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': '_scheme_references'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '193', 'type': 'if_statement', 'children': ['194', '196']},{'id': '194', 'type': 'not_operator', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'scheme_reference'},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'raise_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'LookupError'},{'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': '"was unable to find {0} in scheme reference."'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '207', 'type': 'for_statement', 'children': ['208', '209', '212']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'reference_key'},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'scheme_reference'},{'id': '211', 'type': 'string', 'children': [], 'value': "'keys'"},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '218']},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'updated_scheme'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'reference_key'},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'scheme_key'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'updated_scheme'},{'id': '228', 'type': 'return_statement', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'scheme'}
def _update_scheme(self, scheme, ancestors): if not isinstance(ancestors, OrderedDict): raise TypeError("ancestors must be an OrderedDict. type: {0} was passed.".format(type(ancestors))) if not isinstance(scheme, dict): raise TypeError('scheme must be a dict. type: {0} was passed'.format(type(scheme))) definitions = ROOT_SCHEME.get('_') if 'inherit' in scheme: scheme = self._scheme_propagation(scheme, definitions) updated_scheme = {} for scheme_key in six.iterkeys(scheme): if not isinstance(scheme_key, six.string_types): raise TypeError('scheme keys are required to be strings. type: {0} was passed.'.format(scheme_key)) if '@' in scheme_key: ref = scheme_key[1:] scheme_reference = self._scheme_references.get(ref) if not scheme_reference: raise ConfigValidationException(ancestors, ref, scheme_reference, 'required', scheme) for reference_key in scheme_reference['keys']: scheme_reference['scheme'].update(scheme[scheme_key]) updated_scheme[reference_key] = scheme_reference['scheme'] elif '~' in scheme_key: ref = scheme_key[1:] scheme_reference = self._scheme_references.get(ref) if not scheme_reference: raise LookupError("was unable to find {0} in scheme reference.".format(ref)) for reference_key in scheme_reference['keys']: updated_scheme[reference_key] = scheme[scheme_key] scheme.update(updated_scheme) return scheme
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_walk_tree'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '73', '94', '105', '142', '163', '173', '207', '244', '254', '262']},{'id': '17', 'type': 'if_statement', 'children': ['18', '21']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '26', '46']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '25', 'type': 'string', 'children': [], 'value': "'root'"},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '29', 'type': 'binary_operator', 'children': ['30', '32'], 'value': '+'},{'id': '30', 'type': 'list', 'children': ['31'], 'value': "['registries']"},{'id': '31', 'type': 'string', 'children': [], 'value': "'registries'"},{'id': '32', 'type': 'list_comprehension', 'children': ['33', '34', '41']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '34', 'type': 'for_in_clause', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'if_clause', 'children': ['42']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'not'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '44', 'type': 'tuple', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': "'registries'"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '54', 'type': 'argument_list', 'children': ['55', '60']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '62', 'type': 'lambda', 'children': ['63', '65']},{'id': '63', 'type': 'lambda_parameters', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'if_statement', 'children': ['74', '77', '79']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'is'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '76', 'type': 'None', 'children': []},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'return_statement', 'children': []},{'id': '79', 'type': 'elif_clause', 'children': ['80', '88']},{'id': '80', 'type': 'not_operator', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'raise_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': "'property_name must be a string.'"},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'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': '_update_ancestors'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103', '104']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '105', 'type': 'if_statement', 'children': ['106', '111', '127']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'if_statement', 'children': ['113', '121']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '120'], 'value': '!='},{'id': '114', 'type': 'subscript', 'children': ['115', '119']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '119', 'type': 'integer', 'children': [], 'value': '0'},{'id': '120', 'type': 'string', 'children': [], 'value': "'root'"},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'raise_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'LookupError'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'string', 'children': [], 'value': "'root must be the first item in ancestors.'"},{'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': 'TypeError'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'string', 'children': [], 'value': "'ancestors must be an OrderedDict. {0} was passed'"},{'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': 'ancestors'},{'id': '142', 'type': 'if_statement', 'children': ['143', '149']},{'id': '143', 'type': 'not_operator', 'children': ['144']},{'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': 'scheme'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'raise_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'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': "'scheme must be a dict. {0} was passed.'"},{'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': 'type'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '_update_scheme'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '173', 'type': 'if_statement', 'children': ['174', '179']},{'id': '174', 'type': 'boolean_operator', 'children': ['175', '178'], 'value': 'and'},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': 'is'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '177', 'type': 'None', 'children': []},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '183', 'type': 'conditional_expression', 'children': ['184', '199', '206'], 'value': 'if'},{'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': '_get_cascading_attr'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '190', 'type': 'list_splat', 'children': ['191']},{'id': '191', 'type': 'subscript', 'children': ['192', '196']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '196', 'type': 'slice', 'children': ['197', '198']},{'id': '197', 'type': 'integer', 'children': [], 'value': '1'},{'id': '198', 'type': 'colon', 'children': []},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': "'cascading'"},{'id': '205', 'type': 'False', 'children': []},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '207', 'type': 'for_statement', 'children': ['208', '209', '227']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '212', 'type': 'identifier', 'children': [], 'value': '__execute_validations'},{'id': '213', 'type': 'argument_list', 'children': ['214', '221', '222', '223', '224']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '218', 'type': 'argument_list', 'children': ['219', '220']},{'id': '219', 'type': 'string', 'children': [], 'value': "'is'"},{'id': '220', 'type': 'dictionary', 'children': []},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'if_statement', 'children': ['229', '230', '233']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'raise_statement', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '233', 'type': 'else_clause', 'children': ['234']},{'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': 'self'},{'id': '239', 'type': 'identifier', 'children': [], 'value': '_create_attr'},{'id': '240', 'type': 'argument_list', 'children': ['241', '242', '243']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '248', 'type': 'identifier', 'children': [], 'value': '__validate_unrecognized_values'},{'id': '249', 'type': 'argument_list', 'children': ['250', '251', '252', '253']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': '__populate_scheme_references'},{'id': '259', 'type': 'argument_list', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '266', 'type': 'identifier', 'children': [], 'value': '__validate_config_properties'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269', '270', '271']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'prefix'}
def _walk_tree(self, data, scheme, ancestors=None, property_name=None, prefix=None): if property_name is None: property_name = 'root' order = ['registries'] + [key for key in scheme.keys() if key not in ('registries',)] scheme = OrderedDict(sorted(scheme.items(), key=lambda x: order.index(x[0]))) if data is None: return elif not isinstance(property_name, six.string_types): raise TypeError('property_name must be a string.') ancestors = self._update_ancestors(data, property_name, ancestors) if isinstance(ancestors, OrderedDict): if list(ancestors)[0] != 'root': raise LookupError('root must be the first item in ancestors.') else: raise TypeError('ancestors must be an OrderedDict. {0} was passed'.format(type(ancestors))) if not isinstance(scheme, dict): raise TypeError('scheme must be a dict. {0} was passed.'.format(type(scheme))) scheme = self._update_scheme(scheme, ancestors) if property_name is not None and data: data = self._get_cascading_attr( property_name, *list(ancestors)[1:] ) if scheme.get('cascading', False) else data for err in self.__execute_validations(scheme.get('is', {}), data, property_name, ancestors, prefix=prefix): if err: raise err else: self._create_attr(property_name, data, ancestors) self.__validate_unrecognized_values(scheme, data, ancestors, prefix) self.__populate_scheme_references(scheme, property_name) self.__validate_config_properties(scheme, data, ancestors, prefix)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__execute_validations'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'validations'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'negation'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '37', '58', '81', '103', '130']},{'id': '16', 'type': 'if_statement', 'children': ['17', '23']},{'id': '17', 'type': 'not_operator', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'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': 'TypeError'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': '"ancestors must be an OrderedDict. type: {0} was passed."'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '37', 'type': 'if_statement', 'children': ['38', '44']},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'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': 'validations'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'raise_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': "'validations is required to be a dict. type: {1} was passed.'"},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'validations'},{'id': '58', 'type': 'if_statement', 'children': ['59', '67']},{'id': '59', 'type': 'not_operator', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'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': 'TypeError'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': '"property_key must be a string. type: {0} was passed."'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '88'], 'value': '+'},{'id': '85', 'type': 'list', 'children': ['86', '87'], 'value': "['type', 'required']"},{'id': '86', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '87', 'type': 'string', 'children': [], 'value': "'required'"},{'id': '88', 'type': 'list_comprehension', 'children': ['89', '90', '97']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'validations'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '96', 'type': 'argument_list', 'children': []},{'id': '97', 'type': 'if_clause', 'children': ['98']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'not'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '100', 'type': 'tuple', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': "'required'"},{'id': '102', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ordered_validations'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '111', 'type': 'argument_list', 'children': ['112', '117']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'validations'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '119', 'type': 'lambda', 'children': ['120', '122']},{'id': '120', 'type': 'lambda_parameters', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'for_statement', 'children': ['131', '134', '140']},{'id': '131', 'type': 'pattern_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'validation'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ordered_validations'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'if_statement', 'children': ['142', '145', '193']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'in'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'validation'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'VALIDATORS'},{'id': '145', 'type': 'block', 'children': ['146', '169']},{'id': '146', 'type': 'if_statement', 'children': ['147', '150']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': '=='},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'validation'},{'id': '149', 'type': 'string', 'children': [], 'value': "'not'"},{'id': '150', 'type': 'block', 'children': ['151', '168']},{'id': '151', 'type': 'for_statement', 'children': ['152', '153', '164']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': '__execute_validations'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159', '160', '161', '162', '163']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'negation'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'yield', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '168', 'type': 'continue_statement', 'children': []},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '189']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '171', 'type': 'call', 'children': ['172', '182']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'string', 'children': [], 'value': "'_{0}'"},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'validation'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184', '185', '186', '187', '188']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ancestors'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'negation'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'yield', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '193', 'type': 'else_clause', 'children': ['194']},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'raise_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'LookupError'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': '"{0} isn\'t a validator or reserved scheme key."'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'validation'}
def __execute_validations(self, validations, data, property_name, ancestors, negation=False, prefix=None): if not isinstance(ancestors, OrderedDict): raise TypeError("ancestors must be an OrderedDict. type: {0} was passed.".format(type(ancestors))) if not isinstance(validations, dict): raise TypeError('validations is required to be a dict. type: {1} was passed.'.format(type(validations))) if not isinstance(property_name, six.string_types): raise TypeError("property_key must be a string. type: {0} was passed.".format(type(property_name))) order = ['type', 'required'] + [key for key in validations.keys() if key not in ('required', 'type')] ordered_validations = OrderedDict(sorted(validations.items(), key=lambda x: order.index(x[0]))) for validation, value in six.iteritems(ordered_validations): if validation in VALIDATORS: if validation == 'not': for err in self.__execute_validations(value, data, property_name, ancestors, negation, prefix): yield err continue for err in getattr(self, '_{0}'.format(validation))(value, data, property_name, ancestors, negation, prefix): yield err else: raise LookupError("{0} isn't a validator or reserved scheme key.".format(validation))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'users_feature'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '5', 'type': 'block', 'children': ['6', '25', '33', '40', '47', '53', '59', '76', '83', '90', '98', '136', '143', '184']},{'id': '6', 'type': 'if_statement', 'children': ['7', '17']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '14']},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "'USER_JWT_SECRET'"},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'raise_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'JwtSecretMissing'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': "'Please set USER_JWT_SECRET in config'"},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'session_interface'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'BoilerSessionInterface'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'user_service'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'init'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'login_manager'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'init_app'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'login_manager'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'login_view'},{'id': '52', 'type': 'string', 'children': [], 'value': "'user.login'"},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'login_manager'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'login_message'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'decorated_definition', 'children': ['60', '64']},{'id': '60', 'type': 'decorator', 'children': ['61']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'login_manager'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'user_loader'},{'id': '64', 'type': 'function_definition', 'children': ['65', '66', '68']},{'id': '65', 'type': 'function_name', 'children': [], 'value': 'load_user'},{'id': '66', 'type': 'parameters', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'user_service'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'id'},{'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': 'oauth'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'init_app'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'OauthProviders'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'providers'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'get_providers'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'with_statement', 'children': ['99', '106']},{'id': '99', 'type': 'with_clause', 'children': ['100']},{'id': '100', 'type': 'with_item', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'app_context'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'providers'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'if_statement', 'children': ['112', '117']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'not'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'oauth'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'remote_apps'},{'id': '117', 'type': 'block', 'children': ['118', '129']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'oauth'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'remote_app'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '125', 'type': 'dictionary_splat', 'children': ['126']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'providers'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'register_token_getter'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'provider'},{'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': 'principal'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'init_app'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '143', 'type': 'decorated_definition', 'children': ['144', '148']},{'id': '144', 'type': 'decorator', 'children': ['145']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'principal'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'identity_loader'},{'id': '148', 'type': 'function_definition', 'children': ['149', '150', '151']},{'id': '149', 'type': 'function_name', 'children': [], 'value': 'load_identity'},{'id': '150', 'type': 'parameters', 'children': []},{'id': '151', 'type': 'block', 'children': ['152', '164', '172', '180']},{'id': '152', 'type': 'if_statement', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'current_user'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'return_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'Identity'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'current_user'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'id'},{'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': 'session'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171']},{'id': '170', 'type': 'string', 'children': [], 'value': "'identity.name'"},{'id': '171', 'type': 'None', 'children': []},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179']},{'id': '178', 'type': 'string', 'children': [], 'value': "'identity.auth_type'"},{'id': '179', 'type': 'None', 'children': []},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'AnonymousIdentity'},{'id': '183', 'type': 'argument_list', 'children': []},{'id': '184', 'type': 'decorated_definition', 'children': ['185', '192']},{'id': '185', 'type': 'decorator', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'identity_loaded'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'connect_via'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '192', 'type': 'function_definition', 'children': ['193', '194', '197']},{'id': '193', 'type': 'function_name', 'children': [], 'value': 'on_identity_loaded'},{'id': '194', 'type': 'parameters', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'sender'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '197', 'type': 'block', 'children': ['198', '204', '211', '225']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'current_user'},{'id': '204', 'type': 'if_statement', 'children': ['205', '209']},{'id': '205', 'type': 'not_operator', 'children': ['206']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'current_user'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'return_statement', 'children': []},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '218']},{'id': '213', 'type': 'attribute', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'provides'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'UserNeed'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'current_user'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '225', 'type': 'for_statement', 'children': ['226', '227', '230']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'role'},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'current_user'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '230', 'type': 'block', 'children': ['231']},{'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': 'identity'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'provides'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'RoleNeed'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'role'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'handle'}
def users_feature(app): if not app.config.get('USER_JWT_SECRET', None): raise x.JwtSecretMissing('Please set USER_JWT_SECRET in config') app.session_interface = BoilerSessionInterface() user_service.init(app) login_manager.init_app(app) login_manager.login_view = 'user.login' login_manager.login_message = None @login_manager.user_loader def load_user(id): return user_service.get(id) oauth.init_app(app) registry = OauthProviders(app) providers = registry.get_providers() with app.app_context(): for provider in providers: if provider not in oauth.remote_apps: oauth.remote_app(provider, **providers[provider]) registry.register_token_getter(provider) principal.init_app(app) @principal.identity_loader def load_identity(): if current_user.is_authenticated: return Identity(current_user.id) session.pop('identity.name', None) session.pop('identity.auth_type', None) return AnonymousIdentity() @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): identity.user = current_user if not current_user.is_authenticated: return identity.provides.add(UserNeed(current_user.id)) for role in current_user.roles: identity.provides.add(RoleNeed(role.handle))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'match'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'block', 'children': ['7', '9', '16']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "''' This is a noisy terminal-printing function at present since there is no need to make it a proper API function.'''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'colortext'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': '"FASTA Match"'},{'id': '16', 'type': 'for_statement', 'children': ['17', '20', '28']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'frompdbID'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'fromchains'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'block', 'children': ['29', '33', '37', '118', '122', '134', '177']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'matched_pdbs'},{'id': '32', 'type': 'dictionary', 'children': []},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'matched_chains'},{'id': '36', 'type': 'dictionary', 'children': []},{'id': '37', 'type': 'for_statement', 'children': ['38', '41', '46']},{'id': '38', 'type': 'pattern_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'fromchain'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'fromsequence'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'fromchains'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'for_statement', 'children': ['48', '51', '56']},{'id': '48', 'type': 'pattern_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'topdbID'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'tochains'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'for_statement', 'children': ['58', '61', '66']},{'id': '58', 'type': 'pattern_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'tochain'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'tosequence'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'tochains'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '=='},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'fromsequence'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'tosequence'},{'id': '71', 'type': 'block', 'children': ['72', '86', '95', '107']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'matched_pdbs'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'topdbID'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'matched_pdbs'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'topdbID'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'matched_pdbs'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'topdbID'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'fromchain'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '100']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'matched_chains'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'fromchain'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'matched_chains'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'fromchain'},{'id': '106', 'type': 'list', 'children': [], 'value': '[]'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '114']},{'id': '109', 'type': 'attribute', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'matched_chains'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'fromchain'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'tuple', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'topdbID'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'tochain'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'foundmatches'},{'id': '121', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'colortext'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'printf'},{'id': '127', 'type': 'argument_list', 'children': ['128', '131']},{'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '%'},{'id': '129', 'type': 'string', 'children': [], 'value': '" %s"'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'frompdbID'},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '133', 'type': 'string', 'children': [], 'value': '"silver"'},{'id': '134', 'type': 'for_statement', 'children': ['135', '138', '143']},{'id': '135', 'type': 'pattern_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'mpdbID'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'mchains'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'matched_pdbs'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '142', 'type': 'argument_list', 'children': []},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'if_statement', 'children': ['145', '155']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '=='},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'mchains'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'fromchains'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '154', 'type': 'argument_list', 'children': []},{'id': '155', 'type': 'block', 'children': ['156', '163']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'foundmatches'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'mpdbID'},{'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': 'colortext'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'printf'},{'id': '168', 'type': 'argument_list', 'children': ['169', '174']},{'id': '169', 'type': 'binary_operator', 'children': ['170', '171'], 'value': '%'},{'id': '170', 'type': 'string', 'children': [], 'value': '" PDB %s matched PDB %s on all chains"'},{'id': '171', 'type': 'tuple', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'mpdbID'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'frompdbID'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '176', 'type': 'string', 'children': [], 'value': '"white"'},{'id': '177', 'type': 'if_statement', 'children': ['178', '179', '266']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'foundmatches'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'for_statement', 'children': ['181', '184', '189']},{'id': '181', 'type': 'pattern_list', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'fromchain'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'fromsequence'},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'fromchains'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '188', 'type': 'argument_list', 'children': []},{'id': '189', 'type': 'block', 'children': ['190', '203', '220', '224', '252']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'colortext'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'printf'},{'id': '195', 'type': 'argument_list', 'children': ['196', '200']},{'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '%'},{'id': '197', 'type': 'string', 'children': [], 'value': '" %s"'},{'id': '198', 'type': '()', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'fromchain'},{'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '202', 'type': 'string', 'children': [], 'value': '"silver"'},{'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': 'colortext'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'printf'},{'id': '208', 'type': 'argument_list', 'children': ['209', '213']},{'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '%'},{'id': '210', 'type': 'string', 'children': [], 'value': '" %s"'},{'id': '211', 'type': '()', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'fromsequence'},{'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'color'},{'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': 'unique_sequences'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'fromsequence'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'mstr'},{'id': '223', 'type': 'list', 'children': [], 'value': '[]'},{'id': '224', 'type': 'for_statement', 'children': ['225', '226', '229']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'mchain'},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'matched_chains'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'fromchain'},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'if_statement', 'children': ['231', '236']},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '235'], 'value': 'in'},{'id': '232', 'type': 'subscript', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'mchain'},{'id': '234', 'type': 'integer', 'children': [], 'value': '0'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'foundmatches'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'mstr'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '%'},{'id': '244', 'type': 'string', 'children': [], 'value': '"%s chain %s"'},{'id': '245', 'type': 'tuple', 'children': ['246', '249']},{'id': '246', 'type': 'subscript', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'mchain'},{'id': '248', 'type': 'integer', 'children': [], 'value': '0'},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'mchain'},{'id': '251', 'type': 'integer', 'children': [], 'value': '1'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'colortext'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'printf'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'binary_operator', 'children': ['259', '260'], 'value': '%'},{'id': '259', 'type': 'string', 'children': [], 'value': '"\t Matches: %s"'},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': '", "'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'mstr'},{'id': '266', 'type': 'else_clause', 'children': ['267']},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'colortext'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'string', 'children': [], 'value': '" No matches found."'}
def match(self, other): ''' This is a noisy terminal-printing function at present since there is no need to make it a proper API function.''' colortext.message("FASTA Match") for frompdbID, fromchains in sorted(self.iteritems()): matched_pdbs = {} matched_chains = {} for fromchain, fromsequence in fromchains.iteritems(): for topdbID, tochains in other.iteritems(): for tochain, tosequence in tochains.iteritems(): if fromsequence == tosequence: matched_pdbs[topdbID] = matched_pdbs.get(topdbID, set()) matched_pdbs[topdbID].add(fromchain) matched_chains[fromchain] = matched_chains.get(fromchain, []) matched_chains[fromchain].append((topdbID, tochain)) foundmatches = [] colortext.printf(" %s" % frompdbID, color="silver") for mpdbID, mchains in matched_pdbs.iteritems(): if mchains == set(fromchains.keys()): foundmatches.append(mpdbID) colortext.printf(" PDB %s matched PDB %s on all chains" % (mpdbID, frompdbID), color="white") if foundmatches: for fromchain, fromsequence in fromchains.iteritems(): colortext.printf(" %s" % (fromchain), color = "silver") colortext.printf(" %s" % (fromsequence), color = self.unique_sequences[fromsequence]) mstr = [] for mchain in matched_chains[fromchain]: if mchain[0] in foundmatches: mstr.append("%s chain %s" % (mchain[0], mchain[1])) colortext.printf(" Matches: %s" % ", ".join(mstr)) else: colortext.error(" No matches found.")
{'id': '0', 'type': 'ERROR', 'children': ['1', '2', '7', '9', '15', '19', '26', '33', '36', '37', '40', '46', '48', '49', '50', '51', '54', '55', '56', '57', '60', '61', '62', '63', '69', '72', '82', '86', '91', '101', '116', '126', '131', '171', '179', '211', '214', '215', '219', '222', '223', '226', '227', '230', '233', '252', '256', '259', '276', '280', '283']},{'id': '1', 'type': 'identifier', 'children': [], 'value': 'generateSummaryHTMLTable'},{'id': '2', 'type': 'parameters', 'children': ['3', '4']},{'id': '3', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'extraLapse'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'TYPICAL_LAPSE'},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''Generates a summary in HTML of the status of the expected scripts broken based on the log.\n\t\t\tThis summary is returned as a list of strings. \n\t\t'''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'scriptsRun'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'scriptsRun'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'html'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': '"<table style=\'text-align:center;border:1px solid black;margin-left: auto;margin-right: auto;\'>\\n"'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': '\'\t<tr><td colspan="4" style="text-align:center"></td></tr>\\n\''},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '36', 'type': 'string', 'children': [], 'value': "'"},{'id': '37', 'type': 'ERROR', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'tr'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42', '45'], 'value': '-'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'font'},{'id': '42', 'type': 'ERROR', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'bold'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'background'},{'id': '46', 'type': 'ERROR', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'tablestyle'},{'id': '49', 'type': 'ERROR', 'children': []},{'id': '50', 'type': 'ERROR', 'children': []},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '-'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'background'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'warningstyle'},{'id': '55', 'type': 'ERROR', 'children': []},{'id': '56', 'type': 'ERROR', 'children': []},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '-'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'background'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'failstyle'},{'id': '61', 'type': 'ERROR', 'children': []},{'id': '62', 'type': 'ERROR', 'children': []},{'id': '63', 'type': 'slice', 'children': ['64', '67', '68']},{'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '-'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'background'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '67', 'type': 'colon', 'children': []},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '69', 'type': 'ERROR', 'children': ['70', '71']},{'id': '70', 'type': 'integer', 'children': [], 'value': '0'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'in'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'scriptsRun'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'ERROR', 'children': ['83', '84', '85']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '84', 'type': 'None', 'children': []},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'rowstyle'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'tablestyle'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '%'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '90', 'type': 'integer', 'children': [], 'value': '2'},{'id': '91', 'type': 'boolean_operator', 'children': ['92', '95'], 'value': 'and'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '94', 'type': 'string', 'children': [], 'value': '"lastSuccess"'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'expectedScripts'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '101', 'type': 'ERROR', 'children': ['102', '115']},{'id': '102', 'type': 'ERROR', 'children': ['103', '114']},{'id': '103', 'type': 'not_operator', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'expectedScripts'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110', '113']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '112', 'type': 'string', 'children': [], 'value': '"lastSuccess"'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'extraLapse'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '115', 'type': 'string', 'children': [], 'value': '"STOPPED"'},{'id': '116', 'type': 'ERROR', 'children': ['117', '118', '123', '124', '125']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'rowstyle'},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'failstyle'},{'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '%'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '122', 'type': 'integer', 'children': [], 'value': '2'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '124', 'type': 'string', 'children': [], 'value': '"FAIL"'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'laststatusstyle'},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'tablestyle'},{'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '%'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '130', 'type': 'integer', 'children': [], 'value': '2'},{'id': '131', 'type': 'ERROR', 'children': ['132', '137', '138', '143', '144', '145', '154', '155', '160', '161', '162', '169', '170']},{'id': '132', 'type': 'binary_operator', 'children': ['133', '136'], 'value': '&'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '135', 'type': 'string', 'children': [], 'value': '"status"'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'RETROSPECT_FAIL'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'laststatusstyle'},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'failstyle'},{'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '%'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '142', 'type': 'integer', 'children': [], 'value': '2'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '144', 'type': 'string', 'children': [], 'value': '"FAIL"'},{'id': '145', 'type': 'boolean_operator', 'children': ['146', '149'], 'value': 'and'},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '!='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '148', 'type': 'string', 'children': [], 'value': '"STOPPED"'},{'id': '149', 'type': 'binary_operator', 'children': ['150', '153'], 'value': '&'},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '152', 'type': 'string', 'children': [], 'value': '"status"'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'RETROSPECT_WARNING'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'laststatusstyle'},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'warningstyle'},{'id': '157', 'type': 'binary_operator', 'children': ['158', '159'], 'value': '%'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '159', 'type': 'integer', 'children': [], 'value': '2'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '161', 'type': 'string', 'children': [], 'value': '"WARNINGS"'},{'id': '162', 'type': 'boolean_operator', 'children': ['163', '166'], 'value': 'and'},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': '!='},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '165', 'type': 'string', 'children': [], 'value': '"FAIL"'},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': '!='},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '168', 'type': 'string', 'children': [], 'value': '"STOPPED"'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '170', 'type': 'string', 'children': [], 'value': '"OK"'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '%'},{'id': '177', 'type': 'string', 'children': [], 'value': '\'<tr style="text-align:left;%s">\\n\''},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'rowstyle'},{'id': '179', 'type': 'ERROR', 'children': ['180', '183', '197']},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '=='},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '182', 'type': 'string', 'children': [], 'value': '"STOPPED"'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '%'},{'id': '189', 'type': 'string', 'children': [], 'value': '\'\\t<td style="%s">%s</td>\\n\''},{'id': '190', 'type': 'tuple', 'children': ['191', '196']},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'failstyle'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '%'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '195', 'type': 'integer', 'children': [], 'value': '2'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'binary_operator', 'children': ['203', '204'], 'value': '%'},{'id': '203', 'type': 'string', 'children': [], 'value': '\'\\t<td style="%s">%s</td>\''},{'id': '204', 'type': 'tuple', 'children': ['205', '210']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'tablestyle'},{'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '%'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '209', 'type': 'integer', 'children': [], 'value': '2'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '213', 'type': 'string', 'children': [], 'value': '"lastRun"'},{'id': '214', 'type': 'ERROR', 'children': []},{'id': '215', 'type': 'ERROR', 'children': ['216']},{'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': '=='},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '218', 'type': 'string', 'children': [], 'value': '"STOPPED"'},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '222', 'type': 'string', 'children': [], 'value': "'\\t"},{'id': '223', 'type': 'ERROR', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'td'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '226', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '227', 'type': 'ERROR', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'href'},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '235', '238', '239', '242'], 'value': '<'},{'id': '234', 'type': 'string', 'children': [], 'value': "'\\t"},{'id': '235', 'type': 'ERROR', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'td'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '238', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '239', 'type': 'ERROR', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'href'},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '%'},{'id': '248', 'type': 'string', 'children': [], 'value': '\'\\t<td style="%s">%s</td>\\n\''},{'id': '249', 'type': 'tuple', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'laststatusstyle'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '252', 'type': 'ERROR', 'children': ['253']},{'id': '253', 'type': 'subscript', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '255', 'type': 'string', 'children': [], 'value': '"lastRun"'},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '259', 'type': 'comparison_operator', 'children': ['260', '261', '264', '265', '268'], 'value': '<'},{'id': '260', 'type': 'string', 'children': [], 'value': "'\\t"},{'id': '261', 'type': 'ERROR', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'td'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '264', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '265', 'type': 'ERROR', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'href'},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '%'},{'id': '274', 'type': 'string', 'children': [], 'value': '\'\\t<td style="%s">none found</td>\\n\''},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'laststatusstyle'},{'id': '276', 'type': 'ERROR', 'children': ['277']},{'id': '277', 'type': 'subscript', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '279', 'type': 'string', 'children': [], 'value': '"lastSuccess"'},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '283', 'type': 'comparison_operator', 'children': ['284', '285', '286', '312'], 'value': '<'},{'id': '284', 'type': 'string', 'children': [], 'value': "'\\t"},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'td'},{'id': '286', 'type': 'ERROR', 'children': ['287', '288', '289', '302', '303', '311']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'href'},{'id': '289', 'type': 'call', 'children': ['290', '300']},{'id': '290', 'type': 'attribute', 'children': ['291', '297', '299']},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'string', 'children': [], 'value': "'\\t<td>none found</td>\\n'"},{'id': '297', 'type': 'ERROR', 'children': ['298']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'string', 'children': [], 'value': "'</tr>\\n'"},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '303', 'type': 'call', 'children': ['304', '309']},{'id': '304', 'type': 'attribute', 'children': ['305', '306', '308']},{'id': '305', 'type': 'integer', 'children': [], 'value': '1'},{'id': '306', 'type': 'ERROR', 'children': ['307']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'string', 'children': [], 'value': '"</table>"'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'return'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'html'}
def generateSummaryHTMLTable(self, extraLapse = TYPICAL_LAPSE): '''Generates a summary in HTML of the status of the expected scripts broken based on the log. This summary is returned as a list of strings. ''' scriptsRun = self.scriptsRun html = [] html.append("<table style='text-align:center;border:1px solid black;margin-left: auto;margin-right: auto;'>\n") html.append(' <tr><td colspan="4" style="text-align:center"></td></tr>\n') html.append(' <tr style="font-weight:bold;background-color: tablestyle = ['background-color: warningstyle = ['background-color: failstyle = ['background-color: count = 0 for name, details in sorted(scriptsRun.iteritems()): status = None rowstyle = tablestyle[count % 2] if details["lastSuccess"] and expectedScripts.get(name): if not expectedScripts.check(name, details["lastSuccess"], extraLapse): status = "STOPPED" else: rowstyle = failstyle[count % 2] status = "FAIL" laststatusstyle = tablestyle[count % 2] if details["status"] & RETROSPECT_FAIL: laststatusstyle = failstyle[count % 2] status = "FAIL" elif status != "STOPPED" and details["status"] & RETROSPECT_WARNING: laststatusstyle = warningstyle[count % 2] status = "WARNINGS" elif status != "FAIL" and status != "STOPPED": status = "OK" html.append('<tr style="text-align:left;%s">\n' % rowstyle) if status == "STOPPED": html.append('\t<td style="%s">%s</td>\n' % (failstyle[count % 2], name)) else: html.append('\t<td style="%s">%s</td>' % (tablestyle[count % 2], name)) if details["lastRun"]: if status == "STOPPED": html.append('\t<td style="%s"><a href=" else: html.append('\t<td style="%s"><a href=" else: html.append('\t<td style="%s">%s</td>\n' % (laststatusstyle, status)) if details["lastRun"]: html.append('\t<td style="%s"><a href=" else: html.append('\t<td style="%s">none found</td>\n' % laststatusstyle) if details["lastSuccess"]: html.append('\t<td><a href=" else: html.append('\t<td>none found</td>\n') html.append('</tr>\n') count += 1 html.append("</table>") return html
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'apply_quality_control_checks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'check_gen9_seqs'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'check_short_length'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'check_local_gc_content'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'check_global_gc_content'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '26', '30', '55', '77', '147', '191', '264', '304']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'upper'},{'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': 'failure_reasons'},{'id': '29', 'type': 'list', 'children': [], 'value': '[]'},{'id': '30', 'type': 'if_statement', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'check_short_length'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'if_statement', 'children': ['34', '40']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '39'], 'value': '<'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'min_gene_length'},{'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': 'failure_reasons'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '%'},{'id': '48', 'type': 'string', 'children': [], 'value': "'minimum_length: Sequence is %d bp long and needs to be at least %d bp'"},{'id': '49', 'type': 'tuple', 'children': ['50', '54']},{'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': 'seq'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'min_gene_length'},{'id': '55', 'type': 'if_statement', 'children': ['56', '62']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '61'], 'value': '>'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'max_gene_length'},{'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': 'failure_reasons'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '%'},{'id': '70', 'type': 'string', 'children': [], 'value': "'maximum_length: Sequence is %d bp long and needs to be shorter than %d bp'"},{'id': '71', 'type': 'tuple', 'children': ['72', '76']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'max_gene_length'},{'id': '77', 'type': 'if_statement', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'check_gen9_seqs'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'for_statement', 'children': ['81', '82', '83']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'reserved_restriction_sites'},{'id': '83', 'type': 'block', 'children': ['84', '93', '102', '111', '129']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'dna'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dna_to_re'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'reverse_site'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'dna'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'reverse_complement'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'reverse_pattern'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'dna'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'dna_to_re'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'reverse_site'},{'id': '111', 'type': 'if_statement', 'children': ['112', '118']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'seq'},{'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': 'failure_reasons'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '%'},{'id': '126', 'type': 'string', 'children': [], 'value': "'gen9_restricted_sequences: Reserved sequence %s is present'"},{'id': '127', 'type': '()', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '129', 'type': 'if_statement', 'children': ['130', '136']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'reverse_pattern'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'failure_reasons'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '%'},{'id': '144', 'type': 'string', 'children': [], 'value': "'gen9_restricted_sequences: Reverse-complement of reserved sequence %s is present'"},{'id': '145', 'type': '()', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'site'},{'id': '147', 'type': 'if_statement', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'check_global_gc_content'},{'id': '149', 'type': 'block', 'children': ['150', '159', '175']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'gc_content'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'dna'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'gc_content'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '159', 'type': 'if_statement', 'children': ['160', '163']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': '<'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'gc_content'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'global_gc_content_min'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'failure_reasons'},{'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': "'global_gc_content_min: Global GC content is %.3f%% and must be at least %.3f%%'"},{'id': '172', 'type': 'tuple', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'gc_content'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'global_gc_content_min'},{'id': '175', 'type': 'if_statement', 'children': ['176', '179']},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': '>'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'gc_content'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'global_gc_content_max'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'failure_reasons'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '%'},{'id': '187', 'type': 'string', 'children': [], 'value': "'global_gc_content_max: Global GC content is %.3f%% and must be less than %.3f%%'"},{'id': '188', 'type': 'tuple', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'gc_content'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'global_gc_content_max'},{'id': '191', 'type': 'if_statement', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'check_local_gc_content'},{'id': '193', 'type': 'block', 'children': ['194', '199', '217']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'windows'},{'id': '197', 'type': 'list', 'children': ['198'], 'value': '[seq]'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '199', 'type': 'if_statement', 'children': ['200', '206']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': '<'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'local_gc_window_size'},{'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': 'seq'},{'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': 'windows'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'dna'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'sliding_window'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'local_gc_window_size'},{'id': '217', 'type': 'for_statement', 'children': ['218', '219', '220']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'seq_window'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'windows'},{'id': '220', 'type': 'block', 'children': ['221', '230', '247']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'lgc_content'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'dna'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'gc_content'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'seq_window'},{'id': '230', 'type': 'if_statement', 'children': ['231', '234']},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': '<'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'lgc_content'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'local_gc_content_min'},{'id': '234', 'type': 'block', 'children': ['235', '246']},{'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': 'failure_reasons'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'binary_operator', 'children': ['242', '243'], 'value': '%'},{'id': '242', 'type': 'string', 'children': [], 'value': "'local_gc_content_min: Local GC content is %.3f%% and must be at least %.3f%%'"},{'id': '243', 'type': 'tuple', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'lgc_content'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'local_gc_content_min'},{'id': '246', 'type': 'break_statement', 'children': []},{'id': '247', 'type': 'if_statement', 'children': ['248', '251']},{'id': '248', 'type': 'comparison_operator', 'children': ['249', '250'], 'value': '>'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'lgc_content'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'local_gc_content_max'},{'id': '251', 'type': 'block', 'children': ['252', '263']},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'failure_reasons'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'binary_operator', 'children': ['259', '260'], 'value': '%'},{'id': '259', 'type': 'string', 'children': [], 'value': "'local_gc_content_max: Local GC content is %.3f%% and must be less than %.3f%%'"},{'id': '260', 'type': 'tuple', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'lgc_content'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'local_gc_content_max'},{'id': '263', 'type': 'break_statement', 'children': []},{'id': '264', 'type': 'for_statement', 'children': ['265', '266', '269']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'dna'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'dna_bases'},{'id': '269', 'type': 'block', 'children': ['270', '278']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'homopolymer'},{'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '*'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '275', 'type': 'subscript', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'homopolymer_max_lengths'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '278', 'type': 'if_statement', 'children': ['279', '282']},{'id': '279', 'type': 'comparison_operator', 'children': ['280', '281'], 'value': 'in'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'homopolymer'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '282', 'type': 'block', 'children': ['283']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'call', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'failure_reasons'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'binary_operator', 'children': ['290', '291'], 'value': '%'},{'id': '290', 'type': 'string', 'children': [], 'value': "'max_%s_homopolymer: %s'"},{'id': '291', 'type': 'tuple', 'children': ['292', '297']},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '296', 'type': 'argument_list', 'children': []},{'id': '297', 'type': 'call', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'dna'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'case_highlight'},{'id': '301', 'type': 'argument_list', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'a_homopolymer'},{'id': '304', 'type': 'if_statement', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'failure_reasons'},{'id': '306', 'type': 'block', 'children': ['307', '311']},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'assignment', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'intro'},{'id': '310', 'type': 'string', 'children': [], 'value': '"The given sequence fails following Gen9 design guidelines:"'},{'id': '311', 'type': 'raise_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'binary_operator', 'children': ['321', '323'], 'value': '+'},{'id': '321', 'type': 'list', 'children': ['322'], 'value': '[intro]'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'intro'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'failure_reasons'}
def apply_quality_control_checks( seq, check_gen9_seqs=True, check_short_length=True, check_local_gc_content=True, check_global_gc_content=True): seq = seq.upper() failure_reasons = [] if check_short_length: if len(seq) < min_gene_length: failure_reasons.append('minimum_length: Sequence is %d bp long and needs to be at least %d bp'%(len(seq),min_gene_length)) if len(seq) > max_gene_length: failure_reasons.append('maximum_length: Sequence is %d bp long and needs to be shorter than %d bp'%(len(seq),max_gene_length)) if check_gen9_seqs: for site in reserved_restriction_sites: pattern = dna.dna_to_re(site) reverse_site = dna.reverse_complement(site) reverse_pattern = dna.dna_to_re(reverse_site) if pattern.match(seq): failure_reasons.append('gen9_restricted_sequences: Reserved sequence %s is present'%(site)) if reverse_pattern.match(seq): failure_reasons.append('gen9_restricted_sequences: Reverse-complement of reserved sequence %s is present'%(site)) if check_global_gc_content: gc_content = dna.gc_content(seq) if gc_content < global_gc_content_min: failure_reasons.append('global_gc_content_min: Global GC content is %.3f%% and must be at least %.3f%%'%(gc_content,global_gc_content_min)) if gc_content > global_gc_content_max: failure_reasons.append('global_gc_content_max: Global GC content is %.3f%% and must be less than %.3f%%'%(gc_content,global_gc_content_max)) if check_local_gc_content: windows = [seq] if local_gc_window_size < len(seq): windows = dna.sliding_window(seq, local_gc_window_size) for seq_window in windows: lgc_content = dna.gc_content(seq_window) if lgc_content < local_gc_content_min: failure_reasons.append('local_gc_content_min: Local GC content is %.3f%% and must be at least %.3f%%'%(lgc_content,local_gc_content_min)) break if lgc_content > local_gc_content_max: failure_reasons.append('local_gc_content_max: Local GC content is %.3f%% and must be less than %.3f%%'%(lgc_content,local_gc_content_max)) break for base in dna.dna_bases: homopolymer = base * homopolymer_max_lengths[base] if homopolymer in seq: failure_reasons.append('max_%s_homopolymer: %s'%( base.lower(), dna.case_highlight(seq,a_homopolymer))) if failure_reasons: intro = "The given sequence fails following Gen9 design guidelines:" raise ValueError('\n'.join([intro] + failure_reasons))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'oauth_connect'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '7', 'type': 'block', 'children': ['8', '15', '32', '69', '77', '83', '92', '101', '105', '109', '113', '152', '259', '387', '398']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'valid_actions'},{'id': '11', 'type': 'list', 'children': ['12', '13', '14'], 'value': '["connect", "authorized", "test"]'},{'id': '12', 'type': 'string', 'children': [], 'value': '"connect"'},{'id': '13', 'type': 'string', 'children': [], 'value': '"authorized"'},{'id': '14', 'type': 'string', 'children': [], 'value': '"test"'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_redirect'},{'id': '18', 'type': 'conditional_expression', 'children': ['19', '26', '29'], 'value': 'if'},{'id': '19', 'type': 'attribute', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'views'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Account'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'account_settings'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'login'},{'id': '32', 'type': 'if_statement', 'children': ['33', '63']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '56', '57'], 'value': 'or'},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '48', '49'], 'value': 'or'},{'id': '35', 'type': 'boolean_operator', 'children': ['36', '39', '40'], 'value': 'or'},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'not'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'valid_actions'},{'id': '39', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'not'},{'id': '41', 'type': 'string', 'children': [], 'value': '"oauth"'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '__options__'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': '"registration_methods"'},{'id': '48', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '49', 'type': 'not_operator', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '__options__'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'string', 'children': [], 'value': '"allow_registration"'},{'id': '56', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '57', 'type': 'not_operator', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'oauth'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'redirect'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_redirect'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'oauth'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '__params__'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'me_args'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': '"me"'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'string', 'children': [], 'value': '"user_id"'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'oauth_user_id'},{'id': '104', 'type': 'None', 'children': []},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'oauth_name'},{'id': '108', 'type': 'None', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'oauth_email'},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'if_statement', 'children': ['114', '117']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '=='},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '116', 'type': 'string', 'children': [], 'value': '"test"'},{'id': '117', 'type': 'block', 'children': ['118', '134', '139']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'session_data'},{'id': '121', 'type': 'dictionary', 'children': ['122', '125', '128', '131']},{'id': '122', 'type': 'pair', 'children': ['123', '124']},{'id': '123', 'type': 'string', 'children': [], 'value': '"provider"'},{'id': '124', 'type': 'string', 'children': [], 'value': '"ensure"'},{'id': '125', 'type': 'pair', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': '"user_id"'},{'id': '127', 'type': 'string', 'children': [], 'value': '"1234"'},{'id': '128', 'type': 'pair', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '130', 'type': 'string', 'children': [], 'value': '"Mardix"'},{'id': '131', 'type': 'pair', 'children': ['132', '133']},{'id': '132', 'type': 'string', 'children': [], 'value': '"email"'},{'id': '133', 'type': 'string', 'children': [], 'value': '"[email protected]"'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'set_oauth_session'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'session_data'},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'redirect'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'url_for'},{'id': '145', 'type': 'argument_list', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'oauth'},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'if_statement', 'children': ['153', '156', '202']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': '=='},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '155', 'type': 'string', 'children': [], 'value': '"connect"'},{'id': '156', 'type': 'block', 'children': ['157', '168', '193']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': '_next'},{'id': '160', 'type': 'call', 'children': ['161', '166']},{'id': '161', 'type': 'attribute', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': "'next'"},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'authorized_url'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'url_for'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175', '178', '181', '190']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '180', 'type': 'string', 'children': [], 'value': '"authorized"'},{'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '183', 'type': 'boolean_operator', 'children': ['184', '189'], 'value': 'or'},{'id': '184', 'type': 'boolean_operator', 'children': ['185', '186'], 'value': 'or'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_next'},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'referrer'},{'id': '189', 'type': 'None', 'children': []},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': '_external'},{'id': '192', 'type': 'True', 'children': []},{'id': '193', 'type': 'return_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'authorize'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'authorized_url'},{'id': '202', 'type': 'elif_clause', 'children': ['203', '206']},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': '=='},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '205', 'type': 'string', 'children': [], 'value': '"authorized"'},{'id': '206', 'type': 'block', 'children': ['207', '215']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'authorized_response'},{'id': '214', 'type': 'argument_list', 'children': []},{'id': '215', 'type': 'if_statement', 'children': ['216', '219', '221', '233']},{'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': 'is'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '218', 'type': 'None', 'children': []},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'pass_statement', 'children': []},{'id': '221', 'type': 'elif_clause', 'children': ['222', '227']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'OAuthException'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'flash_error'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'string', 'children': [], 'value': '"Access Denied"'},{'id': '233', 'type': 'else_clause', 'children': ['234']},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'if_statement', 'children': ['236', '238', '248']},{'id': '236', 'type': 'not_operator', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'me_args'},{'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': 'oauth_user_id'},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '248', 'type': 'else_clause', 'children': ['249']},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'me'},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'me_args'},{'id': '259', 'type': 'if_statement', 'children': ['260', '265', '380']},{'id': '260', 'type': 'boolean_operator', 'children': ['261', '264'], 'value': 'and'},{'id': '261', 'type': 'comparison_operator', 'children': ['262', '263'], 'value': '=='},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '263', 'type': 'string', 'children': [], 'value': '"authorized"'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'oauth_user_id'},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'if_statement', 'children': ['267', '270', '320']},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'},{'id': '269', 'type': 'argument_list', 'children': []},{'id': '270', 'type': 'block', 'children': ['271', '309']},{'id': '271', 'type': 'try_statement', 'children': ['272', '296']},{'id': '272', 'type': 'block', 'children': ['273', '285']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'current_user'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'add_federated_login'},{'id': '278', 'type': 'argument_list', 'children': ['279', '282']},{'id': '279', 'type': 'keyword_argument', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'federated_id'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'oauth_user_id'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'flash_success'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'binary_operator', 'children': ['290', '291'], 'value': '%'},{'id': '290', 'type': 'string', 'children': [], 'value': '"You can now login with your %s account"'},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '295', 'type': 'argument_list', 'children': []},{'id': '296', 'type': 'except_clause', 'children': ['297', '301']},{'id': '297', 'type': 'as_pattern', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '299', 'type': 'as_pattern_target', 'children': ['300']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '301', 'type': 'block', 'children': ['302']},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '309', 'type': 'return_statement', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'redirect'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'attribute', 'children': ['314', '319']},{'id': '314', 'type': 'attribute', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'views'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'Account'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'account_settings'},{'id': '320', 'type': 'else_clause', 'children': ['321']},{'id': '321', 'type': 'block', 'children': ['322', '330']},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'assignment', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'with_federation'},{'id': '327', 'type': 'argument_list', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'oauth_user_id'},{'id': '330', 'type': 'if_statement', 'children': ['331', '332', '357']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '332', 'type': 'block', 'children': ['333', '338']},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'create_session'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '338', 'type': 'return_statement', 'children': ['339']},{'id': '339', 'type': 'call', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'redirect'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'boolean_operator', 'children': ['343', '351'], 'value': 'or'},{'id': '343', 'type': 'call', 'children': ['344', '349']},{'id': '344', 'type': 'attribute', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'string', 'children': [], 'value': '"next"'},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': '__options__'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'string', 'children': [], 'value': '"login_view"'},{'id': '357', 'type': 'else_clause', 'children': ['358']},{'id': '358', 'type': 'block', 'children': ['359', '375']},{'id': '359', 'type': 'expression_statement', 'children': ['360']},{'id': '360', 'type': 'assignment', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'session_data'},{'id': '362', 'type': 'dictionary', 'children': ['363', '366', '369', '372']},{'id': '363', 'type': 'pair', 'children': ['364', '365']},{'id': '364', 'type': 'string', 'children': [], 'value': '"provider"'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '366', 'type': 'pair', 'children': ['367', '368']},{'id': '367', 'type': 'string', 'children': [], 'value': '"user_id"'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'oauth_user_id'},{'id': '369', 'type': 'pair', 'children': ['370', '371']},{'id': '370', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'oauth_name'},{'id': '372', 'type': 'pair', 'children': ['373', '374']},{'id': '373', 'type': 'string', 'children': [], 'value': '"email"'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'oauth_email'},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'call', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'set_oauth_session'},{'id': '378', 'type': 'argument_list', 'children': ['379']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'session_data'},{'id': '380', 'type': 'else_clause', 'children': ['381']},{'id': '381', 'type': 'block', 'children': ['382']},{'id': '382', 'type': 'return_statement', 'children': ['383']},{'id': '383', 'type': 'call', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'redirect'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'identifier', 'children': [], 'value': '_redirect'},{'id': '387', 'type': 'return_statement', 'children': ['388']},{'id': '388', 'type': 'dictionary', 'children': ['389', '392', '395']},{'id': '389', 'type': 'pair', 'children': ['390', '391']},{'id': '390', 'type': 'string', 'children': [], 'value': '"action"'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '392', 'type': 'pair', 'children': ['393', '394']},{'id': '393', 'type': 'string', 'children': [], 'value': '"provider"'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'provider'},{'id': '395', 'type': 'pair', 'children': ['396', '397']},{'id': '396', 'type': 'string', 'children': [], 'value': '"authorized_url"'},{'id': '397', 'type': 'string', 'children': [], 'value': '""'},{'id': '398', 'type': 'return_statement', 'children': ['399']},{'id': '399', 'type': 'call', 'children': ['400', '401']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'redirect'},{'id': '401', 'type': 'argument_list', 'children': ['402']},{'id': '402', 'type': 'identifier', 'children': [], 'value': '_redirect'}
def oauth_connect(self, provider, action): valid_actions = ["connect", "authorized", "test"] _redirect = views.auth.Account.account_settings if is_authenticated() else self.login if action not in valid_actions \ or "oauth" not in __options__.get("registration_methods") \ or not __options__.get("allow_registration") \ or not hasattr(oauth, provider): return redirect(_redirect) client = getattr(oauth, provider) params = client.__params__ me_args = params.get("me") user_id = params.get("user_id") oauth_user_id = None oauth_name = None oauth_email = None if action == "test": session_data = { "provider": "ensure", "user_id": "1234", "name": "Mardix", "email": "[email protected]", } set_oauth_session(session_data) return redirect(url_for(self.register, oauth=1)) if action == "connect": _next = request.args.get('next') authorized_url = url_for(self, provider=provider, action="authorized", next=_next or request.referrer or None, _external=True) return client.authorize(callback=authorized_url) elif action == "authorized": resp = client.authorized_response() if resp is None: pass elif isinstance(resp, OAuthException): flash_error("Access Denied") else: if not me_args: oauth_user_id = resp.get(user_id) else: me = client.get(me_args) if action == "authorized" and oauth_user_id: if is_authenticated(): try: current_user.add_federated_login(provider=provider, federated_id=oauth_user_id) flash_success( "You can now login with your %s account" % provider.upper()) except Exception as e: logging.exception(e) return redirect(views.auth.Account.account_settings) else: user = with_federation(provider, oauth_user_id) if user: create_session(user) return redirect(request.args.get("next") or __options__.get( "login_view")) else: session_data = { "provider": provider, "user_id": oauth_user_id, "name": oauth_name, "email": oauth_email, } set_oauth_session(session_data) else: return redirect(_redirect) return { "action": action, "provider": provider, "authorized_url": "" } return redirect(_redirect)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_neighbors'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '16', '25', '29', '186', '195', '206', '210', '237', '246', '266', '284', '298']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''Set neighbors for multi-environments, their slave environments,\n and agents.\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': '"Settings grid neighbors for the multi-environments."'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'tasks'},{'id': '28', 'type': 'list', 'children': [], 'value': '[]'},{'id': '29', 'type': 'for_statement', 'children': ['30', '31', '40']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'len'},{'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': 'grid'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'for_statement', 'children': ['42', '43', '54']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'subscript', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'block', 'children': ['55', '65', '77', '94', '118', '135', '161', '179']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'addr'},{'id': '58', 'type': 'subscript', 'children': ['59', '64']},{'id': '59', 'type': 'subscript', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '72']},{'id': '67', 'type': 'pattern_list', 'children': ['68', '69', '70', '71']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'E'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'S'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'W'},{'id': '72', 'type': 'expression_list', 'children': ['73', '74', '75', '76']},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'None', 'children': []},{'id': '75', 'type': 'None', 'children': []},{'id': '76', 'type': 'None', 'children': []},{'id': '77', 'type': 'if_statement', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '!='},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '80', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'W'},{'id': '85', 'type': 'subscript', 'children': ['86', '93']},{'id': '86', 'type': 'subscript', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '-'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '92', 'type': 'integer', 'children': [], 'value': '1'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '94', 'type': 'if_statement', 'children': ['95', '105']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '!='},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '97', 'type': 'binary_operator', 'children': ['98', '104'], 'value': '-'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '104', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'E'},{'id': '109', 'type': 'subscript', 'children': ['110', '117']},{'id': '110', 'type': 'subscript', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '+'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '116', 'type': 'integer', 'children': [], 'value': '1'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '118', 'type': 'if_statement', 'children': ['119', '122']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '!='},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '121', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'N'},{'id': '126', 'type': 'subscript', 'children': ['127', '132']},{'id': '127', 'type': 'subscript', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '-'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '134', 'type': 'integer', 'children': [], 'value': '1'},{'id': '135', 'type': 'if_statement', 'children': ['136', '148']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': '!='},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '138', 'type': 'binary_operator', 'children': ['139', '147'], 'value': '-'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'subscript', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'integer', 'children': [], 'value': '1'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'S'},{'id': '152', 'type': 'subscript', 'children': ['153', '158']},{'id': '153', 'type': 'subscript', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '+'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ensure_future'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': '_set_node_neighbors'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175', '176', '177', '178']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'addr'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'E'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'S'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'W'},{'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': 'tasks'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'await', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'gather'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'list_splat', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'tasks'},{'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': 'logger'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'concatenated_string', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': '"Setting grid neighbors for the slave environments "'},{'id': '205', 'type': 'string', 'children': [], 'value': '"and their agents."'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'tasks'},{'id': '209', 'type': 'list', 'children': [], 'value': '[]'},{'id': '210', 'type': 'for_statement', 'children': ['211', '212', '215']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'addr'},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'addrs'},{'id': '215', 'type': 'block', 'children': ['216', '230']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'ensure_future'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '227', 'type': 'identifier', 'children': [], 'value': '_set_neighbors'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'addr'},{'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': 'tasks'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'await', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'gather'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'list_splat', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'tasks'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'call', 'children': ['248', '253']},{'id': '248', 'type': 'attribute', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'string', 'children': [], 'value': '"All grid neighbors set in {} seconds."'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'binary_operator', 'children': ['260', '265'], 'value': '-'},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '264', 'type': 'argument_list', 'children': []},{'id': '265', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '269', 'type': 'binary_operator', 'children': ['270', '281'], 'value': '*'},{'id': '270', 'type': 'binary_operator', 'children': ['271', '276'], 'value': '*'},{'id': '271', 'type': 'subscript', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '274', 'type': 'identifier', 'children': [], 'value': '_ngs'},{'id': '275', 'type': 'integer', 'children': [], 'value': '0'},{'id': '276', 'type': 'subscript', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '279', 'type': 'identifier', 'children': [], 'value': '_gs'},{'id': '280', 'type': 'integer', 'children': [], 'value': '0'},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '283', 'type': 'identifier', 'children': [], 'value': '_n_slaves'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '287', 'type': 'binary_operator', 'children': ['288', '293'], 'value': '*'},{'id': '288', 'type': 'subscript', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '291', 'type': 'identifier', 'children': [], 'value': '_ngs'},{'id': '292', 'type': 'integer', 'children': [], 'value': '1'},{'id': '293', 'type': 'subscript', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '296', 'type': 'identifier', 'children': [], 'value': '_gs'},{'id': '297', 'type': 'integer', 'children': [], 'value': '1'},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '305']},{'id': '300', 'type': 'attribute', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '312']},{'id': '307', 'type': 'attribute', 'children': ['308', '311']},{'id': '308', 'type': 'concatenated_string', 'children': ['309', '310']},{'id': '309', 'type': 'string', 'children': [], 'value': '"Initialized a distributed grid with overall size "'},{'id': '310', 'type': 'string', 'children': [], 'value': '"({}, {}). Total of {} agents."'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '312', 'type': 'argument_list', 'children': ['313', '314', '315']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '315', 'type': 'binary_operator', 'children': ['316', '317'], 'value': '*'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'y'}
async def set_neighbors(self): '''Set neighbors for multi-environments, their slave environments, and agents. ''' t = time.time() self.logger.debug("Settings grid neighbors for the multi-environments.") tasks = [] for i in range(len(self.grid)): for j in range(len(self.grid[0])): addr = self.grid[i][j] N, E, S, W = None, None, None, None if i != 0: W = self.grid[i-1][j] if i != len(self.grid) - 1: E = self.grid[i+1][j] if j != 0: N = self.grid[i][j-1] if j != len(self.grid[0]) - 1: S = self.grid[i][j+1] task = asyncio.ensure_future(self._set_node_neighbors(addr, N, E, S, W)) tasks.append(task) await asyncio.gather(*tasks) self.logger.debug("Setting grid neighbors for the slave environments " "and their agents.") tasks = [] for addr in self.addrs: task = asyncio.ensure_future(self._set_neighbors(addr)) tasks.append(task) await asyncio.gather(*tasks) self.logger.debug("All grid neighbors set in {} seconds." .format(time.time() - t)) x = self._ngs[0] * self._gs[0] * self._n_slaves y = self._ngs[1] * self._gs[1] self.logger.info("Initialized a distributed grid with overall size " "({}, {}). Total of {} agents.".format(x, y, x*y))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'vectors'},{'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': 'direction'},{'id': '7', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '32', '50']},{'id': '12', 'type': 'if_statement', 'children': ['13', '19']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'not'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '15', 'type': 'list', 'children': ['16', '17', '18'], 'value': '["all", "incoming", "outgoing"]'},{'id': '16', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '17', 'type': 'string', 'children': [], 'value': '"incoming"'},{'id': '18', 'type': 'string', 'children': [], 'value': '"outgoing"'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'concatenated_string', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': '"{} is not a valid vector direction. "'},{'id': '28', 'type': 'string', 'children': [], 'value': '"Must be all, incoming or outgoing."'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '32', 'type': 'if_statement', 'children': ['33', '39']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'not'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '35', 'type': 'list', 'children': ['36', '37', '38'], 'value': '["all", False, True]'},{'id': '36', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '37', 'type': 'False', 'children': []},{'id': '38', 'type': 'True', 'children': []},{'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': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': '"{} is not a valid vector failed"'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '50', 'type': 'if_statement', 'children': ['51', '54', '139']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '53', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '54', 'type': 'block', 'children': ['55', '91', '115']},{'id': '55', 'type': 'if_statement', 'children': ['56', '59']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '=='},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '58', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '90']},{'id': '62', 'type': 'attribute', 'children': ['63', '88', '89']},{'id': '63', 'type': 'call', 'children': ['64', '70']},{'id': '64', 'type': 'attribute', 'children': ['65', '68', '69']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'Vector'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '68', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'or_'},{'id': '73', 'type': 'argument_list', 'children': ['74', '81']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '=='},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'Vector'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'destination_id'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': '=='},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'Vector'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'origin_id'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '88', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '90', 'type': 'argument_list', 'children': []},{'id': '91', 'type': 'if_statement', 'children': ['92', '95']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '=='},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '94', 'type': 'string', 'children': [], 'value': '"incoming"'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '114']},{'id': '98', 'type': 'attribute', 'children': ['99', '112', '113']},{'id': '99', 'type': 'call', 'children': ['100', '106']},{'id': '100', 'type': 'attribute', 'children': ['101', '104', '105']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'Vector'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '104', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'filter_by'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'destination_id'},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '112', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'if_statement', 'children': ['116', '119']},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': '=='},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '118', 'type': 'string', 'children': [], 'value': '"outgoing"'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'return_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '138']},{'id': '122', 'type': 'attribute', 'children': ['123', '136', '137']},{'id': '123', 'type': 'call', 'children': ['124', '130']},{'id': '124', 'type': 'attribute', 'children': ['125', '128', '129']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'Vector'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '128', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'filter_by'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'origin_id'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '136', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '138', 'type': 'argument_list', 'children': []},{'id': '139', 'type': 'else_clause', 'children': ['140']},{'id': '140', 'type': 'block', 'children': ['141', '185', '212']},{'id': '141', 'type': 'if_statement', 'children': ['142', '145']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '=='},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '144', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '184']},{'id': '148', 'type': 'attribute', 'children': ['149', '182', '183']},{'id': '149', 'type': 'call', 'children': ['150', '156']},{'id': '150', 'type': 'attribute', 'children': ['151', '154', '155']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'Vector'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '154', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'and_'},{'id': '159', 'type': 'argument_list', 'children': ['160', '165']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '164'], 'value': '=='},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'Vector'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'or_'},{'id': '167', 'type': 'argument_list', 'children': ['168', '175']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '172'], 'value': '=='},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'Vector'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'destination_id'},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '179'], 'value': '=='},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'Vector'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'origin_id'},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '182', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '184', 'type': 'argument_list', 'children': []},{'id': '185', 'type': 'if_statement', 'children': ['186', '189']},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': '=='},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '188', 'type': 'string', 'children': [], 'value': '"incoming"'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'return_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '211']},{'id': '192', 'type': 'attribute', 'children': ['193', '209', '210']},{'id': '193', 'type': 'call', 'children': ['194', '200']},{'id': '194', 'type': 'attribute', 'children': ['195', '198', '199']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'Vector'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '198', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'filter_by'},{'id': '200', 'type': 'argument_list', 'children': ['201', '206']},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'destination_id'},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '209', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '211', 'type': 'argument_list', 'children': []},{'id': '212', 'type': 'if_statement', 'children': ['213', '216']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': '=='},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '215', 'type': 'string', 'children': [], 'value': '"outgoing"'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'return_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '238']},{'id': '219', 'type': 'attribute', 'children': ['220', '236', '237']},{'id': '220', 'type': 'call', 'children': ['221', '227']},{'id': '221', 'type': 'attribute', 'children': ['222', '225', '226']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'Vector'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '225', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'filter_by'},{'id': '227', 'type': 'argument_list', 'children': ['228', '233']},{'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'origin_id'},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '236', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '238', 'type': 'argument_list', 'children': []}
def vectors(self, direction="all", failed=False): if direction not in ["all", "incoming", "outgoing"]: raise ValueError( "{} is not a valid vector direction. " "Must be all, incoming or outgoing.".format(direction)) if failed not in ["all", False, True]: raise ValueError("{} is not a valid vector failed".format(failed)) if failed == "all": if direction == "all": return Vector.query\ .filter(or_(Vector.destination_id == self.id, Vector.origin_id == self.id))\ .all() if direction == "incoming": return Vector.query\ .filter_by(destination_id=self.id)\ .all() if direction == "outgoing": return Vector.query\ .filter_by(origin_id=self.id)\ .all() else: if direction == "all": return Vector.query\ .filter(and_(Vector.failed == failed, or_(Vector.destination_id == self.id, Vector.origin_id == self.id)))\ .all() if direction == "incoming": return Vector.query\ .filter_by(destination_id=self.id, failed=failed)\ .all() if direction == "outgoing": return Vector.query\ .filter_by(origin_id=self.id, failed=failed)\ .all()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'transmissions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '7', 'type': 'string', 'children': [], 'value': '"outgoing"'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '10', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '36', '57', '75', '170', '238']},{'id': '15', 'type': 'if_statement', 'children': ['16', '22']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'not'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '18', 'type': 'list', 'children': ['19', '20', '21'], 'value': '["incoming", "outgoing", "all"]'},{'id': '19', 'type': 'string', 'children': [], 'value': '"incoming"'},{'id': '20', 'type': 'string', 'children': [], 'value': '"outgoing"'},{'id': '21', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': '()', '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': 'binary_operator', 'children': ['29', '35'], 'value': '+'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': '"You cannot get transmissions of direction {}."'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '35', 'type': 'string', 'children': [], 'value': '"Type can only be incoming, outgoing or all."'},{'id': '36', 'type': 'if_statement', 'children': ['37', '43']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'not'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '39', 'type': 'list', 'children': ['40', '41', '42'], 'value': '["all", "pending", "received"]'},{'id': '40', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '41', 'type': 'string', 'children': [], 'value': '"pending"'},{'id': '42', 'type': 'string', 'children': [], 'value': '"received"'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'raise_statement', 'children': ['45']},{'id': '45', 'type': '()', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'binary_operator', 'children': ['50', '56'], 'value': '+'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': '"You cannot get transmission of status {}."'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '56', 'type': 'string', 'children': [], 'value': '"Status can only be pending, received or all"'},{'id': '57', 'type': 'if_statement', 'children': ['58', '64']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'not'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '60', 'type': 'list', 'children': ['61', '62', '63'], 'value': '["all", False, True]'},{'id': '61', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '62', 'type': 'False', 'children': []},{'id': '63', 'type': 'True', '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': 'ValueError'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': '"{} is not a valid transmission failed"'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '=='},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '78', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'if_statement', 'children': ['81', '84', '124']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '=='},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '83', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '123']},{'id': '87', 'type': 'attribute', 'children': ['88', '121', '122']},{'id': '88', 'type': 'call', 'children': ['89', '95']},{'id': '89', 'type': 'attribute', 'children': ['90', '93', '94']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '93', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'and_'},{'id': '98', 'type': 'argument_list', 'children': ['99', '104']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': '=='},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '103', 'type': 'False', 'children': []},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'or_'},{'id': '106', 'type': 'argument_list', 'children': ['107', '114']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': '=='},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'destination_id'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '118'], 'value': '=='},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'origin_id'},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '121', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'else_clause', 'children': ['125']},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '169']},{'id': '128', 'type': 'attribute', 'children': ['129', '167', '168']},{'id': '129', 'type': 'call', 'children': ['130', '136']},{'id': '130', 'type': 'attribute', 'children': ['131', '134', '135']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '134', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'and_'},{'id': '139', 'type': 'argument_list', 'children': ['140', '145', '150']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '144'], 'value': '=='},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '144', 'type': 'False', 'children': []},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '149'], 'value': '=='},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'or_'},{'id': '152', 'type': 'argument_list', 'children': ['153', '160']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '157'], 'value': '=='},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'destination_id'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '164'], 'value': '=='},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'origin_id'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '167', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'if_statement', 'children': ['171', '174']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': '=='},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '173', 'type': 'string', 'children': [], 'value': '"incoming"'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'if_statement', 'children': ['176', '179', '202']},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': '=='},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '178', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '201']},{'id': '182', 'type': 'attribute', 'children': ['183', '199', '200']},{'id': '183', 'type': 'call', 'children': ['184', '190']},{'id': '184', 'type': 'attribute', 'children': ['185', '188', '189']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '188', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'filter_by'},{'id': '190', 'type': 'argument_list', 'children': ['191', '194']},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '193', 'type': 'False', 'children': []},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'destination_id'},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '199', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '201', 'type': 'argument_list', 'children': []},{'id': '202', 'type': 'else_clause', 'children': ['203']},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'return_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '237']},{'id': '206', 'type': 'attribute', 'children': ['207', '235', '236']},{'id': '207', 'type': 'call', 'children': ['208', '214']},{'id': '208', 'type': 'attribute', 'children': ['209', '212', '213']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '212', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'and_'},{'id': '217', 'type': 'argument_list', 'children': ['218', '223', '230']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '222'], 'value': '=='},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '222', 'type': 'False', 'children': []},{'id': '223', 'type': 'comparison_operator', 'children': ['224', '227'], 'value': '=='},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'destination_id'},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '230', 'type': 'comparison_operator', 'children': ['231', '234'], 'value': '=='},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '235', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'if_statement', 'children': ['239', '242']},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': '=='},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '241', 'type': 'string', 'children': [], 'value': '"outgoing"'},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'if_statement', 'children': ['244', '247', '270']},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': '=='},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '246', 'type': 'string', 'children': [], 'value': '"all"'},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'return_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '269']},{'id': '250', 'type': 'attribute', 'children': ['251', '267', '268']},{'id': '251', 'type': 'call', 'children': ['252', '258']},{'id': '252', 'type': 'attribute', 'children': ['253', '256', '257']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '256', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'filter_by'},{'id': '258', 'type': 'argument_list', 'children': ['259', '262']},{'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '261', 'type': 'False', 'children': []},{'id': '262', 'type': 'keyword_argument', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'origin_id'},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '267', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '269', 'type': 'argument_list', 'children': []},{'id': '270', 'type': 'else_clause', 'children': ['271']},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'return_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '305']},{'id': '274', 'type': 'attribute', 'children': ['275', '303', '304']},{'id': '275', 'type': 'call', 'children': ['276', '282']},{'id': '276', 'type': 'attribute', 'children': ['277', '280', '281']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '280', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'and_'},{'id': '285', 'type': 'argument_list', 'children': ['286', '291', '298']},{'id': '286', 'type': 'comparison_operator', 'children': ['287', '290'], 'value': '=='},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '290', 'type': 'False', 'children': []},{'id': '291', 'type': 'comparison_operator', 'children': ['292', '295'], 'value': '=='},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'origin_id'},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '298', 'type': 'comparison_operator', 'children': ['299', '302'], 'value': '=='},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'Transmission'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '303', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '305', 'type': 'argument_list', 'children': []}
def transmissions(self, direction="outgoing", status="all", failed=False): if direction not in ["incoming", "outgoing", "all"]: raise(ValueError("You cannot get transmissions of direction {}." .format(direction) + "Type can only be incoming, outgoing or all.")) if status not in ["all", "pending", "received"]: raise(ValueError("You cannot get transmission of status {}." .format(status) + "Status can only be pending, received or all")) if failed not in ["all", False, True]: raise ValueError("{} is not a valid transmission failed" .format(failed)) if direction == "all": if status == "all": return Transmission.query\ .filter(and_(Transmission.failed == False, or_(Transmission.destination_id == self.id, Transmission.origin_id == self.id)))\ .all() else: return Transmission.query\ .filter(and_(Transmission.failed == False, Transmission.status == status, or_(Transmission.destination_id == self.id, Transmission.origin_id == self.id)))\ .all() if direction == "incoming": if status == "all": return Transmission.query\ .filter_by(failed=False, destination_id=self.id)\ .all() else: return Transmission.query\ .filter(and_(Transmission.failed == False, Transmission.destination_id == self.id, Transmission.status == status))\ .all() if direction == "outgoing": if status == "all": return Transmission.query\ .filter_by(failed=False, origin_id=self.id)\ .all() else: return Transmission.query\ .filter(and_(Transmission.failed == False, Transmission.origin_id == self.id, Transmission.status == status))\ .all()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'user_stats'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'block', 'children': ['6', '11', '15', '19', '44', '61', '80', '86', '102', '109', '116', '136', '148', '164', '174', '184', '250', '362']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'timer'},{'id': '9', 'type': 'argument_list', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': "'user_stats'"},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '14', 'type': 'dictionary', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'if_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': 'request'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '24', 'type': 'string', 'children': [], 'value': '"POST"'},{'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': 'data'},{'id': '29', 'type': 'subscript', 'children': ['30', '43']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '34', 'type': 'argument_list', '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': 'request'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '43', 'type': 'string', 'children': [], 'value': '"filters"'},{'id': '44', 'type': 'if_statement', 'children': ['45', '50']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'},{'id': '46', 'type': 'string', 'children': [], 'value': '"filters"'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'GET'},{'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': 'data'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'load_query_json'},{'id': '56', 'type': 'argument_list', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'GET'},{'id': '60', 'type': 'string', 'children': [], 'value': '"filters"'},{'id': '61', 'type': 'if_statement', 'children': ['62', '65']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71', '72', '75']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '71', 'type': 'dictionary', 'children': []},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '74', 'type': 'string', 'children': [], 'value': "'models_user_stats.html'"},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'help_text'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'user_stats'},{'id': '79', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'get_environment'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'if_statement', 'children': ['87', '91']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'is_time_overridden'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'shift_time'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'get_time'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'get_user_id'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'get_language'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '121']},{'id': '118', 'type': 'pattern_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'filter_names'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'filter_filters'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'list_splat', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'reachable_leaves'},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'Item'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'filter_all_reachable_leaves_many'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'filter_filters'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'all_leaves'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'reachable_leaves'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'number_of_answers_more_items'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'all_leaves'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'correct_answers'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'number_of_correct_answers_more_items'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'all_leaves'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '184', 'type': 'if_statement', 'children': ['185', '193']},{'id': '185', 'type': 'call', 'children': ['186', '191']},{'id': '186', 'type': 'attribute', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'GET'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'string', 'children': [], 'value': '"mastered"'},{'id': '193', 'type': 'block', 'children': ['194', '199', '205', '218', '238']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'timer'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'string', 'children': [], 'value': "'user_stats_mastered'"},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'mastery_threshold'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'get_mastery_trashold'},{'id': '204', 'type': 'argument_list', 'children': []},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'predictions'},{'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': 'Item'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'predict_for_overview'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216', '217']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'environment'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'all_leaves'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'mastered'},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'all_leaves'},{'id': '231', 'type': 'list_comprehension', 'children': ['232', '235']},{'id': '232', 'type': 'comparison_operator', 'children': ['233', '234'], 'value': '>='},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'mastery_threshold'},{'id': '235', 'type': 'for_in_clause', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'predictions'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '243', 'type': 'argument_list', 'children': ['244', '245']},{'id': '244', 'type': 'string', 'children': [], 'value': '"user_stats - getting predictions for items took %s seconds"'},{'id': '245', 'type': '()', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'timer'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'string', 'children': [], 'value': "'user_stats_mastered'"},{'id': '250', 'type': 'for_statement', 'children': ['251', '254', '259']},{'id': '251', 'type': 'pattern_list', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '256', 'type': 'argument_list', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'filter_names'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'reachable_leaves'},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'if_statement', 'children': ['261', '267', '282']},{'id': '261', 'type': 'comparison_operator', 'children': ['262', '266'], 'value': '=='},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '266', 'type': 'integer', 'children': [], 'value': '0'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '273']},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '273', 'type': 'dictionary', 'children': ['274', '279']},{'id': '274', 'type': 'pair', 'children': ['275', '276']},{'id': '275', 'type': 'string', 'children': [], 'value': '"filter"'},{'id': '276', 'type': 'subscript', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '279', 'type': 'pair', 'children': ['280', '281']},{'id': '280', 'type': 'string', 'children': [], 'value': '"number_of_items"'},{'id': '281', 'type': 'integer', 'children': [], 'value': '0'},{'id': '282', 'type': 'else_clause', 'children': ['283']},{'id': '283', 'type': 'block', 'children': ['284', '336']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '289']},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '289', 'type': 'dictionary', 'children': ['290', '295', '301', '314', '325']},{'id': '290', 'type': 'pair', 'children': ['291', '292']},{'id': '291', 'type': 'string', 'children': [], 'value': '"filter"'},{'id': '292', 'type': 'subscript', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '295', 'type': 'pair', 'children': ['296', '297']},{'id': '296', 'type': 'string', 'children': [], 'value': '"number_of_items"'},{'id': '297', 'type': 'call', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '301', 'type': 'pair', 'children': ['302', '303']},{'id': '302', 'type': 'string', 'children': [], 'value': '"number_of_practiced_items"'},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '305', 'type': 'generator_expression', 'children': ['306', '311']},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '310'], 'value': '>'},{'id': '307', 'type': 'subscript', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '310', 'type': 'integer', 'children': [], 'value': '0'},{'id': '311', 'type': 'for_in_clause', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '314', 'type': 'pair', 'children': ['315', '316']},{'id': '315', 'type': 'string', 'children': [], 'value': '"number_of_answers"'},{'id': '316', 'type': 'call', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '318', 'type': 'generator_expression', 'children': ['319', '322']},{'id': '319', 'type': 'subscript', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'answers'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '322', 'type': 'for_in_clause', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '325', 'type': 'pair', 'children': ['326', '327']},{'id': '326', 'type': 'string', 'children': [], 'value': '"number_of_correct_answers"'},{'id': '327', 'type': 'call', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '329', 'type': 'generator_expression', 'children': ['330', '333']},{'id': '330', 'type': 'subscript', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'correct_answers'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '333', 'type': 'for_in_clause', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '336', 'type': 'if_statement', 'children': ['337', '345']},{'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': 'request'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'GET'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '343', 'type': 'argument_list', 'children': ['344']},{'id': '344', 'type': 'string', 'children': [], 'value': '"mastered"'},{'id': '345', 'type': 'block', 'children': ['346']},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'assignment', 'children': ['348', '353']},{'id': '348', 'type': 'subscript', 'children': ['349', '352']},{'id': '349', 'type': 'subscript', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '352', 'type': 'string', 'children': [], 'value': '"number_of_mastered_items"'},{'id': '353', 'type': 'call', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '355', 'type': 'generator_expression', 'children': ['356', '359']},{'id': '356', 'type': 'subscript', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'mastered'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '359', 'type': 'for_in_clause', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '362', 'type': 'return_statement', 'children': ['363']},{'id': '363', 'type': 'call', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'render_json'},{'id': '365', 'type': 'argument_list', 'children': ['366', '367', '368', '371']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '368', 'type': 'keyword_argument', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '370', 'type': 'string', 'children': [], 'value': "'models_user_stats.html'"},{'id': '371', 'type': 'keyword_argument', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'help_text'},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'user_stats'},{'id': '375', 'type': 'identifier', 'children': [], 'value': '__doc__'}
def user_stats(request): timer('user_stats') response = {} data = None if request.method == "POST": data = json.loads(request.body.decode("utf-8"))["filters"] if "filters" in request.GET: data = load_query_json(request.GET, "filters") if data is None: return render_json(request, {}, template='models_user_stats.html', help_text=user_stats.__doc__) environment = get_environment() if is_time_overridden(request): environment.shift_time(get_time(request)) user_id = get_user_id(request) language = get_language(request) filter_names, filter_filters = list(zip(*sorted(data.items()))) reachable_leaves = Item.objects.filter_all_reachable_leaves_many(filter_filters, language) all_leaves = sorted(list(set(flatten(reachable_leaves)))) answers = environment.number_of_answers_more_items(all_leaves, user_id) correct_answers = environment.number_of_correct_answers_more_items(all_leaves, user_id) if request.GET.get("mastered"): timer('user_stats_mastered') mastery_threshold = get_mastery_trashold() predictions = Item.objects.predict_for_overview(environment, user_id, all_leaves) mastered = dict(list(zip(all_leaves, [p >= mastery_threshold for p in predictions]))) LOGGER.debug("user_stats - getting predictions for items took %s seconds", (timer('user_stats_mastered'))) for identifier, items in zip(filter_names, reachable_leaves): if len(items) == 0: response[identifier] = { "filter": data[identifier], "number_of_items": 0, } else: response[identifier] = { "filter": data[identifier], "number_of_items": len(items), "number_of_practiced_items": sum(answers[i] > 0 for i in items), "number_of_answers": sum(answers[i] for i in items), "number_of_correct_answers": sum(correct_answers[i] for i in items), } if request.GET.get("mastered"): response[identifier]["number_of_mastered_items"]= sum(mastered[i] for i in items) return render_json(request, response, template='models_user_stats.html', help_text=user_stats.__doc__)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_resource'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'output_model'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rtype'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'existing_ids'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'id_helper'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '17', '61', '82', '96', '117', '126', '141']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'''\n General-purpose routine to create a new resource in the output model, based on data provided\n output_model - Versa connection to model to be updated\n rtype - Type IRI for the new resource, set with Versa type\n unique - list of key/value pairs for determining a unique hash for the new resource\n links - list of key/value pairs for setting properties on the new resource\n id_helper - If a string, a base URL for the generatd ID. If callable, a function used to return the entity. If None, set a default good enough for testing.\n existing_ids - set of existing IDs to not recreate, or None, in which case a new resource will always be created\n '''"},{'id': '17', 'type': 'if_statement', 'children': ['18', '23', '31', '42', '54']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'id_helper'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'idg'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'idgen'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'id_helper'},{'id': '31', 'type': 'elif_clause', 'children': ['32', '37']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'id_helper'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'GeneratorType'},{'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': 'idg'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'id_helper'},{'id': '42', 'type': 'elif_clause', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'id_helper'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'idg'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'default_idgen'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'else_clause', 'children': ['55']},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'raise_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'string', 'children': [], 'value': "'id_helper must be string (URL), callable or None'"},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68', '69', '70', '73', '76', '79']},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'None', 'children': []},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'output_model'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '72', 'type': 'None', 'children': []},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'idgen'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'idg'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'existing_ids'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'existing_ids'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'extras'},{'id': '81', 'type': 'None', 'children': []},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'materialize_entity'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92', '93']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'rtype'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '96', 'type': 'if_statement', 'children': ['97', '100']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'is'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'existing_ids'},{'id': '99', 'type': 'None', 'children': []},{'id': '100', 'type': 'block', 'children': ['101', '110']},{'id': '101', 'type': 'if_statement', 'children': ['102', '105']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'in'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'existing_ids'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'tuple', 'children': ['108', '109']},{'id': '108', 'type': 'False', 'children': []},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'existing_ids'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'output_model'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'VTYPE_REL'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'rtype'},{'id': '126', 'type': 'for_statement', 'children': ['127', '130', '131']},{'id': '127', 'type': 'pattern_list', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'output_model'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '141', 'type': 'return_statement', 'children': ['142']},{'id': '142', 'type': 'tuple', 'children': ['143', '144']},{'id': '143', 'type': 'True', 'children': []},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'rid'}
def create_resource(output_model, rtype, unique, links, existing_ids=None, id_helper=None): ''' General-purpose routine to create a new resource in the output model, based on data provided output_model - Versa connection to model to be updated rtype - Type IRI for the new resource, set with Versa type unique - list of key/value pairs for determining a unique hash for the new resource links - list of key/value pairs for setting properties on the new resource id_helper - If a string, a base URL for the generatd ID. If callable, a function used to return the entity. If None, set a default good enough for testing. existing_ids - set of existing IDs to not recreate, or None, in which case a new resource will always be created ''' if isinstance(id_helper, str): idg = idgen(id_helper) elif isinstance(id_helper, GeneratorType): idg = id_helper elif id_helper is None: idg = default_idgen(None) else: raise ValueError('id_helper must be string (URL), callable or None') ctx = context(None, None, output_model, base=None, idgen=idg, existing_ids=existing_ids, extras=None) rid = I(materialize_entity(ctx, rtype, unique=unique)) if existing_ids is not None: if rid in existing_ids: return (False, rid) existing_ids.add(rid) output_model.add(rid, VTYPE_REL, rtype) for r, t in links: output_model.add(rid, r, t) return (True, rid)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'patterns'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '52', '58', '90', '101', '109', '125']},{'id': '6', 'type': 'if_statement', 'children': ['7', '20']},{'id': '7', 'type': 'boolean_operator', 'children': ['8', '14'], 'value': 'and'},{'id': '8', 'type': 'not_operator', 'children': ['9']},{'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': 'args'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'pattern_files'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'try_statement', 'children': ['22', '43']},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '32']},{'id': '25', 'type': 'attribute', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '41']},{'id': '34', 'type': 'attribute', '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': 'args'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'except_clause', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'raise_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'LogRaptorArgumentError'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'PATTERN'"},{'id': '51', 'type': 'string', 'children': [], 'value': "'no search pattern'"},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'if_statement', 'children': ['59', '64']},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'pattern_files'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'list_comprehension', 'children': ['72', '78']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '78', 'type': 'for_in_clause', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'fileinput'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'pattern_files'},{'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': 'patterns'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'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': 'logger'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'string', 'children': [], 'value': '"search patterns to be processed: %r"'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '109', 'type': 'if_statement', 'children': ['110', '113']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'in'},{'id': '111', 'type': 'string', 'children': [], 'value': "''"},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '113', 'type': 'block', 'children': ['114', '121']},{'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': 'logger'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': '"an empty pattern provided: match all strings!"'},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'try_statement', 'children': ['126', '174']},{'id': '126', 'type': 'block', 'children': ['127', '144']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '130', 'type': 'conditional_expression', 'children': ['131', '134', '139'], 'value': 'if'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'IGNORECASE'},{'id': '134', 'type': 'attribute', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'case'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '|'},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'UNICODE'},{'id': '144', 'type': 'return_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'list_comprehension', 'children': ['149', '169', '172']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '153', 'type': 'argument_list', 'children': ['154', '166']},{'id': '154', 'type': 'conditional_expression', 'children': ['155', '158', '163'], 'value': 'if'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '%'},{'id': '156', 'type': 'string', 'children': [], 'value': "r'(\\b%s\\b)'"},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '%'},{'id': '164', 'type': 'string', 'children': [], 'value': "'(%s)'"},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '169', 'type': 'for_in_clause', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '172', 'type': 'if_clause', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '174', 'type': 'except_clause', 'children': ['175', '181']},{'id': '175', 'type': 'as_pattern', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '179', 'type': 'as_pattern_target', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'raise_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'LogRaptorArgumentError'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '%'},{'id': '187', 'type': 'string', 'children': [], 'value': "'wrong regex syntax for pattern: %r'"},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'err'}
def patterns(self): if not self.args.patterns and not self.args.pattern_files: try: self.args.patterns.append(self.args.files.pop(0)) except IndexError: raise LogRaptorArgumentError('PATTERN', 'no search pattern') patterns = set() if self.args.pattern_files: patterns.update([p.rstrip('\n') for p in fileinput.input(self.args.pattern_files)]) patterns.update(self.args.patterns) logger.debug("search patterns to be processed: %r", patterns) if '' in patterns: logger.info("an empty pattern provided: match all strings!") return tuple() try: flags = re.IGNORECASE if self.args.case else 0 | re.UNICODE return tuple([ re.compile(r'(\b%s\b)' % pat if self.args.word else '(%s)' % pat, flags=flags) for pat in patterns if pat ]) except re.error as err: raise LogRaptorArgumentError('wrong regex syntax for pattern: %r' % err)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'qualify'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'qualification'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '7', 'type': 'block', 'children': ['8', '15', '21', '27', '37', '47', '55', '121', '128', '138', '152', '181', '191', '198', '214', '224', '240']},{'id': '8', 'type': 'import_from_statement', 'children': ['9', '13']},{'id': '9', 'type': 'dotted_name', 'children': ['10', '11', '12']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'boto'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'mturk'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '13', 'type': 'dotted_name', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'MTurkConnection'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'PsiturkConfig'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'load_config'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'aws_access_key_id'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': "'AWS Access'"},{'id': '36', 'type': 'string', 'children': [], 'value': "'aws_access_key_id'"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'aws_secret_access_key'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': "'AWS Access'"},{'id': '46', 'type': 'string', 'children': [], 'value': "'aws_secret_access_key'"},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'MTurkConnection'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'aws_access_key_id'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'aws_secret_access_key'},{'id': '55', 'type': 'function_definition', 'children': ['56', '57', '59']},{'id': '56', 'type': 'function_name', 'children': [], 'value': 'get_workers_with_qualification'},{'id': '57', 'type': 'parameters', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'qualification'},{'id': '59', 'type': 'block', 'children': ['60', '64', '68', '72', '119']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '63', 'type': 'list', 'children': [], 'value': '[]'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'continue_flag'},{'id': '67', 'type': 'True', 'children': []},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'while_statement', 'children': ['73', '75']},{'id': '73', 'type': '()', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'continue_flag'},{'id': '75', 'type': 'block', 'children': ['76', '91']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'new_results'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'get_qualifications_for_qualification_type'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '88']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'qualification'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '87', 'type': 'integer', 'children': [], 'value': '100'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'page_number'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '91', 'type': 'if_statement', 'children': ['92', '99', '104']},{'id': '92', 'type': '()', 'children': ['93']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '98'], 'value': '=='},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'new_results'},{'id': '98', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'continue_flag'},{'id': '103', 'type': 'False', 'children': []},{'id': '104', 'type': 'else_clause', 'children': ['105']},{'id': '105', 'type': 'block', 'children': ['106', '113']},{'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': 'results'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'new_results'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '+'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'return_statement', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'get_workers_with_qualification'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'qualification'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '131', 'type': 'list_comprehension', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'SubjectId'},{'id': '135', 'type': 'for_in_clause', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': '"Assigning qualification {} with value {} to worker {}"'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150', '151']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'qualification'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '152', 'type': 'if_statement', 'children': ['153', '156', '168']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': 'in'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'update_qualification_score'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166', '167']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'qualification'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '168', 'type': 'else_clause', 'children': ['169']},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'assign_qualification'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179', '180']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'qualification'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '181', 'type': 'if_statement', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'get_workers_with_qualification'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'qualification'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'string', 'children': [], 'value': '"{} workers with qualification {}:"'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '208', 'type': 'argument_list', 'children': ['209', '213']},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'qualification'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '217', 'type': 'list_comprehension', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'IntegerValue'},{'id': '221', 'type': 'for_in_clause', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'unique_values'},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'list_comprehension', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'IntegerValue'},{'id': '237', 'type': 'for_in_clause', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '240', 'type': 'for_statement', 'children': ['241', '242', '243']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'unique_values'},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'string', 'children': [], 'value': '"{} with value {}"'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '254', 'type': 'argument_list', 'children': ['255', '267']},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'list_comprehension', 'children': ['259', '260', '263']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '260', 'type': 'for_in_clause', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '263', 'type': 'if_clause', 'children': ['264']},{'id': '264', 'type': 'comparison_operator', 'children': ['265', '266'], 'value': '=='},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'v'}
def qualify(qualification, value, worker): from boto.mturk.connection import MTurkConnection config = PsiturkConfig() config.load_config() aws_access_key_id = config.get('AWS Access', 'aws_access_key_id') aws_secret_access_key = config.get('AWS Access', 'aws_secret_access_key') conn = MTurkConnection(aws_access_key_id, aws_secret_access_key) def get_workers_with_qualification(qualification): results = [] continue_flag = True page = 1 while(continue_flag): new_results = conn.get_qualifications_for_qualification_type( qualification, page_size=100, page_number=page) if(len(new_results) == 0): continue_flag = False else: results.extend(new_results) page = page + 1 return results results = get_workers_with_qualification(qualification) workers = [x.SubjectId for x in results] click.echo( "Assigning qualification {} with value {} to worker {}".format( qualification, value, worker)) if worker in workers: result = conn.update_qualification_score(qualification, worker, value) else: result = conn.assign_qualification(qualification, worker, value) if result: click.echo(result) results = get_workers_with_qualification(qualification) click.echo("{} workers with qualification {}:".format( len(results), qualification)) values = [r.IntegerValue for r in results] unique_values = list(set([r.IntegerValue for r in results])) for v in unique_values: click.echo("{} with value {}".format( len([val for val in values if val == v]), v))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup_jobs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'outpath'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '7', 'type': 'block', 'children': ['8', '10', '14', '18', '22', '142', '153', '161', '169', '173', '209', '220', '255', '286', '301', '338']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "''' This function sets up the jobs by creating the necessary input files as expected.\n - outpath is where the output is to be stored.\n - options is the optparse options object.\n - input_files is a list of paths to input files.\n '''"},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'job_inputs'},{'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': 'reverse_mapping'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'fasta_file_contents'},{'id': '21', 'type': 'dictionary', 'children': []},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '25', 'type': 'block', 'children': ['26', '36']},{'id': '26', 'type': 'assert_statement', 'children': ['27']},{'id': '27', 'type': '()', 'children': ['28']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': '()', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'fasta_file_contents'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '36', 'type': 'if_statement', 'children': ['37', '48', '129']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '39', 'type': 'generator_expression', 'children': ['40', '45']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'fnmatch'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'pdb_file_wildcards'},{'id': '48', 'type': 'block', 'children': ['49', '61', '81', '114']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'PDB'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'from_filepath'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '60', 'type': 'True', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'pdb_id'},{'id': '66', 'type': 'subscript', 'children': ['67', '80']},{'id': '67', 'type': 'call', 'children': ['68', '78']},{'id': '68', 'type': 'attribute', 'children': ['69', '77']},{'id': '69', 'type': 'call', 'children': ['70', '75']},{'id': '70', 'type': 'attribute', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '80', 'type': 'integer', 'children': [], 'value': '0'},{'id': '81', 'type': 'if_statement', 'children': ['82', '99']},{'id': '82', 'type': 'boolean_operator', 'children': ['83', '91'], 'value': 'and'},{'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': 'pdb'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'pdb_id'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'string', 'children': [], 'value': "'pdb'"},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '98'], 'value': '>='},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'pdb_id'},{'id': '98', 'type': 'integer', 'children': [], 'value': '7'},{'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': 'pdb'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'pdb_id'},{'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': 'pdb'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'pdb_id'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': "'pdb'"},{'id': '113', 'type': 'string', 'children': [], 'value': "''"},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '119']},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'fasta_file_contents'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '119', 'type': 'tuple', 'children': ['120', '128']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'create_fasta'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'prefer_seqres_order'},{'id': '127', 'type': 'False', 'children': []},{'id': '128', 'type': 'string', 'children': [], 'value': "'PDB'"},{'id': '129', 'type': 'else_clause', 'children': ['130']},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '136']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'fasta_file_contents'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '136', 'type': 'tuple', 'children': ['137', '141']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'read_file'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'input_file'},{'id': '141', 'type': 'string', 'children': [], 'value': "'FASTA'"},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '148']},{'id': '144', 'type': 'pattern_list', 'children': ['145', '146', '147']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'found_sequences'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'reverse_mapping'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'get_sequences'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'fasta_file_contents'},{'id': '153', 'type': 'if_statement', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'found_sequences'},{'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': 'reformat'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'found_sequences'},{'id': '161', 'type': 'if_statement', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'expression_list', 'children': ['166', '167', '168']},{'id': '166', 'type': 'None', 'children': []},{'id': '167', 'type': 'False', 'children': []},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'desired_sequences'},{'id': '172', 'type': 'dictionary', 'children': []},{'id': '173', 'type': 'for_statement', 'children': ['174', '177', '182']},{'id': '174', 'type': 'pattern_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'found_sequences'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '181', 'type': 'argument_list', 'children': []},{'id': '182', 'type': 'block', 'children': ['183', '190']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '189']},{'id': '185', 'type': 'pattern_list', 'children': ['186', '187', '188']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'pdb_id'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '190', 'type': 'if_statement', 'children': ['191', '202']},{'id': '191', 'type': 'boolean_operator', 'children': ['192', '197'], 'value': 'or'},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '196'], 'value': 'is'},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '196', 'type': 'None', 'children': []},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': '=='},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '202', 'type': 'block', 'children': ['203']},{'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': 'desired_sequences'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '214']},{'id': '211', 'type': 'pattern_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'job_inputs'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'create_inputs'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218', '219']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'outpath'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'desired_sequences'},{'id': '220', 'type': 'if_statement', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'reverse_mapping'},{'id': '222', 'type': 'block', 'children': ['223', '235', '244']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'segment_mapping_file'},{'id': '226', 'type': 'call', 'children': ['227', '232']},{'id': '227', 'type': 'attribute', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '232', 'type': 'argument_list', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'outpath'},{'id': '234', 'type': 'string', 'children': [], 'value': '"segment_map.json"'},{'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': 'colorprinter'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'binary_operator', 'children': ['242', '243'], 'value': '%'},{'id': '242', 'type': 'string', 'children': [], 'value': '"Creating a reverse mapping file %s."'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'segment_mapping_file'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'write_file'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'segment_mapping_file'},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'reverse_mapping'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'post_processing_script'},{'id': '258', 'type': 'call', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'read_file'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '267']},{'id': '262', 'type': 'attribute', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '267', 'type': 'argument_list', 'children': ['268', '285']},{'id': '268', 'type': 'subscript', 'children': ['269', '284']},{'id': '269', 'type': 'call', 'children': ['270', '275']},{'id': '270', 'type': 'attribute', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'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': 'realpath'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': '__file__'},{'id': '284', 'type': 'integer', 'children': [], 'value': '0'},{'id': '285', 'type': 'string', 'children': [], 'value': "'post_processing.py'"},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'write_file'},{'id': '289', 'type': 'argument_list', 'children': ['290', '299', '300']},{'id': '290', 'type': 'call', 'children': ['291', '296']},{'id': '291', 'type': 'attribute', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '296', 'type': 'argument_list', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'outpath'},{'id': '298', 'type': 'string', 'children': [], 'value': "'post_processing.py'"},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'post_processing_script'},{'id': '300', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '301', 'type': 'if_statement', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'secondary_structure_file'},{'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': 'write_file'},{'id': '309', 'type': 'argument_list', 'children': ['310', '319', '337']},{'id': '310', 'type': 'call', 'children': ['311', '316']},{'id': '311', 'type': 'attribute', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '316', 'type': 'argument_list', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'outpath'},{'id': '318', 'type': 'string', 'children': [], 'value': "'ss_filter.json'"},{'id': '319', 'type': 'call', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'dictionary', 'children': ['325']},{'id': '325', 'type': 'pair', 'children': ['326', '327']},{'id': '326', 'type': 'string', 'children': [], 'value': "'secondary_structure_filter'"},{'id': '327', 'type': 'attribute', 'children': ['328', '336']},{'id': '328', 'type': 'call', 'children': ['329', '332']},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'SecondaryStructureDefinition'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'from_filepath'},{'id': '332', 'type': 'argument_list', 'children': ['333']},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'secondary_structure_file'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '337', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '338', 'type': 'return_statement', 'children': ['339']},{'id': '339', 'type': 'expression_list', 'children': ['340', '341', '344']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'job_inputs'},{'id': '341', 'type': 'comparison_operator', 'children': ['342', '343'], 'value': '!='},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'reverse_mapping'},{'id': '343', 'type': 'None', 'children': []},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'errors'}
def setup_jobs(outpath, options, input_files): ''' This function sets up the jobs by creating the necessary input files as expected. - outpath is where the output is to be stored. - options is the optparse options object. - input_files is a list of paths to input files. ''' job_inputs = None reverse_mapping = None fasta_file_contents = {} for input_file in input_files: assert(not(fasta_file_contents.get(input_file))) if any(fnmatch(input_file, x) for x in pdb_file_wildcards): pdb = PDB.from_filepath(input_file, strict=True) pdb.pdb_id = os.path.basename(input_file).split('.')[0] if pdb.pdb_id.startswith('pdb') and len(pdb.pdb_id) >= 7: pdb.pdb_id = pdb.pdb_id.replace('pdb', '') fasta_file_contents[input_file] = (pdb.create_fasta(prefer_seqres_order = False), 'PDB') else: fasta_file_contents[input_file] = (read_file(input_file), 'FASTA') found_sequences, reverse_mapping, errors = get_sequences(options, fasta_file_contents) if found_sequences: reformat(found_sequences) if errors: return None, False, errors desired_sequences = {} for key, sequence in found_sequences.iteritems(): pdb_id, chain, file_name = key if options.chain is None or chain == options.chain: desired_sequences[key] = sequence job_inputs, errors = create_inputs(options, outpath, desired_sequences) if reverse_mapping: segment_mapping_file = os.path.join(outpath, "segment_map.json") colorprinter.message("Creating a reverse mapping file %s." % segment_mapping_file) write_file(segment_mapping_file, json.dumps(reverse_mapping)) post_processing_script = read_file(os.path.join(os.path.split(os.path.realpath(__file__))[0], 'post_processing.py')) write_file(os.path.join(outpath, 'post_processing.py'), post_processing_script, 'w') if options.secondary_structure_file: write_file(os.path.join(outpath, 'ss_filter.json'), json.dumps({'secondary_structure_filter' : SecondaryStructureDefinition.from_filepath(options.secondary_structure_file).data}), 'w') return job_inputs, reverse_mapping != None, errors
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_stdlib'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '7', '12', '49', '74', '96', '105', '192']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'string', 'children': [], 'value': "'''Scans sys.path for standard library modules.\n '''"},{'id': '7', 'type': 'if_statement', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': '_stdlib'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_stdlib'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'prefixes'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'set_comprehension', 'children': ['19', '27']},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '29', 'type': 'tuple', 'children': ['30', '33', '41']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '37', 'type': 'string', 'children': [], 'value': "'real_prefix'"},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '45', 'type': 'string', 'children': [], 'value': "'base_prefix'"},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '49', 'type': 'for_statement', 'children': ['50', '51', '54']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sp'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '54', 'type': 'block', 'children': ['55', '60']},{'id': '55', 'type': 'if_statement', 'children': ['56', '58']},{'id': '56', 'type': 'not_operator', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sp'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'continue_statement', 'children': []},{'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': '_import_paths'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sp'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'stdpaths'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'set_comprehension', 'children': ['81', '82', '85']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_import_paths'},{'id': '85', 'type': 'if_clause', 'children': ['86']},{'id': '86', 'type': 'boolean_operator', 'children': ['87', '93'], 'value': 'and'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'prefixes'},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'not'},{'id': '94', 'type': 'string', 'children': [], 'value': "'site-packages'"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'p'},{'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': '_stdlib'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'builtin_module_names'},{'id': '105', 'type': 'for_statement', 'children': ['106', '107', '108']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'stdpath'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'stdpaths'},{'id': '108', 'type': 'block', 'children': ['109', '121']},{'id': '109', 'type': 'if_statement', 'children': ['110', '119']},{'id': '110', 'type': 'not_operator', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '117']},{'id': '112', 'type': 'attribute', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'stdpath'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'continue_statement', 'children': []},{'id': '121', 'type': 'for_statement', 'children': ['122', '123', '129']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'stdpath'},{'id': '129', 'type': 'block', 'children': ['130', '143', '155', '177']},{'id': '130', 'type': 'if_statement', 'children': ['131', '141']},{'id': '131', 'type': 'boolean_operator', 'children': ['132', '138'], 'value': 'or'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': '=='},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '140', 'type': 'string', 'children': [], 'value': "'site-packages'"},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'continue_statement', 'children': []},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '146', 'type': 'call', 'children': ['147', '152']},{'id': '147', 'type': 'attribute', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'stdpath'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '155', 'type': 'if_statement', 'children': ['156', '175']},{'id': '156', 'type': 'boolean_operator', 'children': ['157', '166'], 'value': 'and'},{'id': '157', 'type': 'not_operator', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '166', 'type': 'not_operator', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'tuple', 'children': ['173', '174']},{'id': '173', 'type': 'string', 'children': [], 'value': "'.py'"},{'id': '174', 'type': 'string', 'children': [], 'value': "'.so'"},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'continue_statement', 'children': []},{'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': '_stdlib'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'subscript', 'children': ['184', '191']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190']},{'id': '189', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '190', 'type': 'integer', 'children': [], 'value': '1'},{'id': '191', 'type': 'integer', 'children': [], 'value': '0'},{'id': '192', 'type': 'return_statement', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': '_stdlib'}
def load_stdlib(): '''Scans sys.path for standard library modules. ''' if _stdlib: return _stdlib prefixes = tuple({os.path.abspath(p) for p in ( sys.prefix, getattr(sys, 'real_prefix', sys.prefix), getattr(sys, 'base_prefix', sys.prefix), )}) for sp in sys.path: if not sp: continue _import_paths.append(os.path.abspath(sp)) stdpaths = tuple({p for p in _import_paths if p.startswith(prefixes) and 'site-packages' not in p}) _stdlib.update(sys.builtin_module_names) for stdpath in stdpaths: if not os.path.isdir(stdpath): continue for item in os.listdir(stdpath): if item.startswith('.') or item == 'site-packages': continue p = os.path.join(stdpath, item) if not os.path.isdir(p) and not item.endswith(('.py', '.so')): continue _stdlib.add(item.split('.', 1)[0]) return _stdlib
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_python_script'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '5', 'type': 'block', 'children': ['6', '8', '22', '35', '78']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''Checks a file to see if it's a python script of some sort.\n '''"},{'id': '8', 'type': 'if_statement', 'children': ['9', '19']},{'id': '9', 'type': 'call', 'children': ['10', '17']},{'id': '10', 'type': 'attribute', 'children': ['11', '16']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "'.py'"},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'True', 'children': []},{'id': '22', 'type': 'if_statement', 'children': ['23', '32']},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'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': 'os'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'False', 'children': []},{'id': '35', 'type': 'try_statement', 'children': ['36', '74']},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'with_statement', 'children': ['38', '48', '73']},{'id': '38', 'type': 'with_clause', 'children': ['39']},{'id': '39', 'type': 'with_item', 'children': ['40']},{'id': '40', 'type': 'as_pattern', 'children': ['41', '46']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '45', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '46', 'type': 'as_pattern_target', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '48', 'type': 'ERROR', 'children': ['49']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '56', '59'], 'value': '!='},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'integer', 'children': [], 'value': '2'},{'id': '56', 'type': 'ERROR', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'return'},{'id': '58', 'type': 'False', 'children': []},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': "r'.*python'"},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'str_'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'block', 'children': [], 'value': ''},{'id': '74', 'type': 'except_clause', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'pass_statement', 'children': []},{'id': '78', 'type': 'return_statement', 'children': ['79']},{'id': '79', 'type': 'False', 'children': []}
def is_python_script(filename): '''Checks a file to see if it's a python script of some sort. ''' if filename.lower().endswith('.py'): return True if not os.path.isfile(filename): return False try: with open(filename, 'rb') as fp: if fp.read(2) != b' return False return re.match(r'.*python', str_(fp.readline())) except IOError: pass return False
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fit'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '7', 'type': 'float', 'children': [], 'value': '1e-8'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'max_iterations'},{'id': '10', 'type': 'integer', 'children': [], 'value': '10'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'save_results'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '28', '36', '41', '55', '89', '107', '112', '280']},{'id': '18', 'type': 'import_from_statement', 'children': ['19', '24', '26']},{'id': '19', 'type': 'dotted_name', 'children': ['20', '21', '22', '23']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'disco'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'pipeline'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '24', 'type': 'dotted_name', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Worker'},{'id': '26', 'type': 'dotted_name', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'Stage'},{'id': '28', 'type': 'import_from_statement', 'children': ['29', '32', '34']},{'id': '29', 'type': 'dotted_name', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'disco'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '32', 'type': 'dotted_name', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'Job'},{'id': '34', 'type': 'dotted_name', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'result_iterator'},{'id': '36', 'type': 'import_statement', 'children': ['37']},{'id': '37', 'type': 'aliased_import', 'children': ['38', '40']},{'id': '38', 'type': 'dotted_name', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '41', 'type': 'if_statement', 'children': ['42', '49']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '48'], 'value': '=='},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '47', 'type': 'string', 'children': [], 'value': '"y_map"'},{'id': '48', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'Exception'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': '"Logistic regression requires a target label mapping parameter."'},{'id': '55', 'type': 'try_statement', 'children': ['56', '81']},{'id': '56', 'type': 'block', 'children': ['57', '64', '71']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'max_iterations'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'max_iterations'},{'id': '71', 'type': 'if_statement', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': '<'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'max_iterations'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'raise_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': '"Parameter max_iterations should be greater than 0."'},{'id': '81', 'type': 'except_clause', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'raise_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': '"Parameters should be numerical."'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'thetas'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'binary_operator', 'children': ['98', '106'], 'value': '+'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'subscript', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '105', 'type': 'string', 'children': [], 'value': '"X_indices"'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'J'},{'id': '110', 'type': 'list', 'children': ['111'], 'value': '[0]'},{'id': '111', 'type': 'integer', 'children': [], 'value': '0'},{'id': '112', 'type': 'for_statement', 'children': ['113', '114', '118']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'max_iterations'},{'id': '118', 'type': 'block', 'children': ['119', '133', '173', '181', '189', '210', '221', '248']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'Job'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'worker'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'Worker'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'save_results'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'save_results'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'pipeline'},{'id': '138', 'type': 'list', 'children': ['139', '158'], 'value': '[\n ("split", Stage("map", input_chain=dataset.params["input_chain"], init=simple_init, process=map_fit)),\n (\'group_all\', Stage("reduce", init=simple_init, process=reduce_fit, combine=True))]'},{'id': '139', 'type': 'tuple', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': '"split"'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'Stage'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145', '152', '155']},{'id': '144', 'type': 'string', 'children': [], 'value': '"map"'},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'input_chain'},{'id': '147', 'type': 'subscript', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '151', 'type': 'string', 'children': [], 'value': '"input_chain"'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'init'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'simple_init'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'map_fit'},{'id': '158', 'type': 'tuple', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': "'group_all'"},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'Stage'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164', '167', '170']},{'id': '163', 'type': 'string', 'children': [], 'value': '"reduce"'},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'init'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'simple_init'},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'reduce_fit'},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'combine'},{'id': '172', 'type': 'True', 'children': []},{'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': 'job'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '188']},{'id': '183', 'type': 'subscript', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '187', 'type': 'string', 'children': [], 'value': '"thetas"'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'thetas'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '194', 'type': 'argument_list', 'children': ['195', '203']},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '%'},{'id': '198', 'type': 'string', 'children': [], 'value': '"logreg_fit_iter_%d"'},{'id': '199', 'type': '()', 'children': ['200']},{'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '+'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '202', 'type': 'integer', 'children': [], 'value': '1'},{'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '205', 'type': 'subscript', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '209', 'type': 'string', 'children': [], 'value': '"data_tag"'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'fitmodel_url'},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '221', 'type': 'for_statement', 'children': ['222', '225', '229']},{'id': '222', 'type': 'pattern_list', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'result_iterator'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'fitmodel_url'},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'if_statement', 'children': ['231', '234', '242']},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': '=='},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '233', 'type': 'string', 'children': [], 'value': '"J"'},{'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': 'J'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '242', 'type': 'else_clause', 'children': ['243']},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'thetas'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '248', 'type': 'if_statement', 'children': ['249', '265']},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '264'], 'value': '<'},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'binary_operator', 'children': ['256', '260'], 'value': '-'},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'J'},{'id': '258', 'type': 'unary_operator', 'children': ['259'], 'value': '-'},{'id': '259', 'type': 'integer', 'children': [], 'value': '2'},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'J'},{'id': '262', 'type': 'unary_operator', 'children': ['263'], 'value': '-'},{'id': '263', 'type': 'integer', 'children': [], 'value': '1'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '265', 'type': 'block', 'children': ['266', '279']},{'id': '266', 'type': 'if_statement', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'show'},{'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': 'print'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '%'},{'id': '274', 'type': 'string', 'children': [], 'value': '"Converged at iteration %d"'},{'id': '275', 'type': '()', 'children': ['276']},{'id': '276', 'type': 'binary_operator', 'children': ['277', '278'], 'value': '+'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '278', 'type': 'integer', 'children': [], 'value': '1'},{'id': '279', 'type': 'break_statement', 'children': []},{'id': '280', 'type': 'return_statement', 'children': ['281']},{'id': '281', 'type': 'dictionary', 'children': ['282']},{'id': '282', 'type': 'pair', 'children': ['283', '284']},{'id': '283', 'type': 'string', 'children': [], 'value': '"logreg_fitmodel"'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'fitmodel_url'}
def fit(dataset, alpha=1e-8, max_iterations=10, save_results=True, show=False): from disco.worker.pipeline.worker import Worker, Stage from disco.core import Job, result_iterator import numpy as np if dataset.params["y_map"] == []: raise Exception("Logistic regression requires a target label mapping parameter.") try: alpha = float(alpha) max_iterations = int(max_iterations) if max_iterations < 1: raise Exception("Parameter max_iterations should be greater than 0.") except ValueError: raise Exception("Parameters should be numerical.") thetas = np.zeros(len(dataset.params["X_indices"]) + 1) J = [0] for i in range(max_iterations): job = Job(worker=Worker(save_results=save_results)) job.pipeline = [ ("split", Stage("map", input_chain=dataset.params["input_chain"], init=simple_init, process=map_fit)), ('group_all', Stage("reduce", init=simple_init, process=reduce_fit, combine=True))] job.params = dataset.params job.params["thetas"] = thetas job.run(name="logreg_fit_iter_%d" % (i + 1), input=dataset.params["data_tag"]) fitmodel_url = job.wait(show=show) for k, v in result_iterator(fitmodel_url): if k == "J": J.append(v) else: thetas = v if np.abs(J[-2] - J[-1]) < alpha: if show: print("Converged at iteration %d" % (i + 1)) break return {"logreg_fitmodel": fitmodel_url}
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'draw_image'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'xmin'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ymin'},{'id': '11', 'type': 'integer', 'children': [], 'value': '0'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ymax'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '34', '49', '73', '93', '113', '133', '153', '161']},{'id': '19', 'type': 'if_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '+'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'xmin'},{'id': '29', 'type': 'subscript', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ymax'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ymax'},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '+'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ymin'},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'bitmap_list'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'dictionary', 'children': ['58', '61', '64', '67', '70']},{'id': '58', 'type': 'pair', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': "'image'"},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '61', 'type': 'pair', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'xmin'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'xmin'},{'id': '64', 'type': 'pair', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': "'xmax'"},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'id': '67', 'type': 'pair', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'ymin'"},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ymin'},{'id': '70', 'type': 'pair', 'children': ['71', '72']},{'id': '71', 'type': 'string', 'children': [], 'value': "'ymax'"},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'ymax'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'xmin'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '78', 'type': 'generator_expression', 'children': ['79', '80', '89']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '80', 'type': 'for_in_clause', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '82', 'type': 'tuple', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'xmin'},{'id': '84', 'type': 'subscript', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '88', 'type': 'string', 'children': [], 'value': "'xmin'"},{'id': '89', 'type': 'if_clause', 'children': ['90']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'is'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '92', 'type': 'None', 'children': []},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ymin'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '98', 'type': 'generator_expression', 'children': ['99', '100', '109']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '100', 'type': 'for_in_clause', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '102', 'type': 'tuple', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'ymin'},{'id': '104', 'type': 'subscript', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '108', 'type': 'string', 'children': [], 'value': "'ymin'"},{'id': '109', 'type': 'if_clause', 'children': ['110']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '118', 'type': 'generator_expression', 'children': ['119', '120', '129']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '120', 'type': 'for_in_clause', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '122', 'type': 'tuple', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'id': '124', 'type': 'subscript', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '128', 'type': 'string', 'children': [], 'value': "'xmax'"},{'id': '129', 'type': 'if_clause', 'children': ['130']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'is'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '132', 'type': 'None', 'children': []},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'ymax'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '138', 'type': 'generator_expression', 'children': ['139', '140', '149']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '140', 'type': 'for_in_clause', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '142', 'type': 'tuple', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'ymax'},{'id': '144', 'type': 'subscript', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '148', 'type': 'string', 'children': [], 'value': "'ymax'"},{'id': '149', 'type': 'if_clause', 'children': ['150']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': 'is'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '152', 'type': 'None', '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': 'set_xlimits'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'xmin'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'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': 'self'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'set_ylimits'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ymin'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ymax'}
def draw_image(self, image, xmin=0, ymin=0, xmax=None, ymax=None): if xmax is None: xmax = xmin + image.size[0] if ymax is None: ymax = ymin + image.size[1] self.bitmap_list.append({'image': image, 'xmin': xmin, 'xmax': xmax, 'ymin': ymin, 'ymax': ymax}) xmin = min(x for x in (xmin, self.limits['xmin']) if x is not None) ymin = min(y for y in (ymin, self.limits['ymin']) if y is not None) xmax = max(x for x in (xmax, self.limits['xmax']) if x is not None) ymax = max(y for y in (ymax, self.limits['ymax']) if y is not None) self.set_xlimits(xmin, xmax) self.set_ylimits(ymin, ymax)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_prepare_data'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '22', '28', '151', '157']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '11']},{'id': '8', 'type': 'pattern_list', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'xmin'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'id': '11', 'type': 'expression_list', 'children': ['12', '17']},{'id': '12', 'type': 'subscript', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '16', 'type': 'string', 'children': [], 'value': "'xmin'"},{'id': '17', 'type': 'subscript', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '21', 'type': 'string', 'children': [], 'value': "'xmax'"},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'prepared_plot_series_list'},{'id': '27', 'type': 'list', 'children': [], 'value': '[]'},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '33']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'plot_series_list'},{'id': '33', 'type': 'block', 'children': ['34', '42', '48', '60', '142']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'prepared_series'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'prepared_series'},{'id': '47', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '55']},{'id': '50', 'type': 'pattern_list', 'children': ['51', '52', '53', '54']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'list_splat', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '60', 'type': 'if_statement', 'children': ['61', '70']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '66'], 'value': '=='},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '70', 'type': 'block', 'children': ['71', '80', '109', '131']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '80', 'type': 'if_statement', 'children': ['81', '84', '103']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'is'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'xmin'},{'id': '83', 'type': 'None', 'children': []},{'id': '84', 'type': 'block', 'children': ['85', '94']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'xmin'},{'id': '94', 'type': 'if_statement', 'children': ['95', '98']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '>'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'augmented_assignment', 'children': ['101', '102'], 'value': '-='},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'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', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '108', 'type': 'None', 'children': []},{'id': '109', 'type': 'if_statement', 'children': ['110', '113', '125']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'max_idx'},{'id': '117', 'type': 'binary_operator', 'children': ['118', '124'], 'value': '+'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'id': '124', 'type': 'integer', 'children': [], 'value': '1'},{'id': '125', 'type': 'else_clause', 'children': ['126']},{'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': 'max_idx'},{'id': '130', 'type': 'None', 'children': []},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '136']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'prepared_series'},{'id': '135', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '138', 'type': 'slice', 'children': ['139', '140', '141']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '140', 'type': 'colon', 'children': []},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'max_idx'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '149']},{'id': '144', 'type': 'attribute', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'prepared_plot_series_list'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'prepared_series'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'prepared_shaded_regions_list'},{'id': '156', 'type': 'list', 'children': [], 'value': '[]'},{'id': '157', 'type': 'for_statement', 'children': ['158', '159', '162']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'shaded_regions_list'},{'id': '162', 'type': 'block', 'children': ['163', '171', '177', '188', '270']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'prepared_series'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '170', 'type': 'argument_list', 'children': []},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'prepared_series'},{'id': '176', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '183']},{'id': '179', 'type': 'pattern_list', 'children': ['180', '181', '182']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '181', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '182', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'list_splat', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '188', 'type': 'if_statement', 'children': ['189', '198']},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '194'], 'value': '=='},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '198', 'type': 'block', 'children': ['199', '208', '237', '259']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '208', 'type': 'if_statement', 'children': ['209', '212', '231']},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '211'], 'value': 'is'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'xmin'},{'id': '211', 'type': 'None', 'children': []},{'id': '212', 'type': 'block', 'children': ['213', '222']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'xmin'},{'id': '222', 'type': 'if_statement', 'children': ['223', '226']},{'id': '223', 'type': 'comparison_operator', 'children': ['224', '225'], 'value': '>'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '225', 'type': 'integer', 'children': [], 'value': '0'},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'augmented_assignment', 'children': ['229', '230'], 'value': '-='},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '230', 'type': 'integer', 'children': [], 'value': '1'},{'id': '231', 'type': 'else_clause', 'children': ['232']},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '236', 'type': 'None', 'children': []},{'id': '237', 'type': 'if_statement', 'children': ['238', '241', '253']},{'id': '238', 'type': 'comparison_operator', 'children': ['239', '240'], 'value': 'is'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'id': '240', 'type': 'None', 'children': []},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'max_idx'},{'id': '245', 'type': 'binary_operator', 'children': ['246', '252'], 'value': '+'},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'xmax'},{'id': '252', 'type': 'integer', 'children': [], 'value': '1'},{'id': '253', 'type': 'else_clause', 'children': ['254']},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'max_idx'},{'id': '258', 'type': 'None', 'children': []},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '264']},{'id': '261', 'type': 'subscript', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'prepared_series'},{'id': '263', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '264', 'type': 'subscript', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '266', 'type': 'slice', 'children': ['267', '268', '269']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'min_idx'},{'id': '268', 'type': 'colon', 'children': []},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'max_idx'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '277']},{'id': '272', 'type': 'attribute', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'prepared_shaded_regions_list'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'prepared_series'}
def _prepare_data(self): xmin, xmax = self.limits['xmin'], self.limits['xmax'] self.prepared_plot_series_list = [] for series in self.plot_series_list: prepared_series = series.copy() data = prepared_series['data'] x, _, _, _ = zip(*data) if sorted(x) == list(x): x = np.array(x) if xmin is not None: min_idx = x.searchsorted(xmin) if min_idx > 0: min_idx -= 1 else: min_idx = None if xmax is not None: max_idx = x.searchsorted(xmax) + 1 else: max_idx = None prepared_series['data'] = data[min_idx:max_idx] self.prepared_plot_series_list.append(prepared_series) self.prepared_shaded_regions_list = [] for series in self.shaded_regions_list: prepared_series = series.copy() data = prepared_series['data'] x, _, _ = zip(*data) if sorted(x) == list(x): x = np.array(x) if xmin is not None: min_idx = x.searchsorted(xmin) if min_idx > 0: min_idx -= 1 else: min_idx = None if xmax is not None: max_idx = x.searchsorted(xmax) + 1 else: max_idx = None prepared_series['data'] = data[min_idx:max_idx] self.prepared_shaded_regions_list.append(prepared_series)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_departures'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stop_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'api_key'},{'id': '9', 'type': 'block', 'children': ['10', '16', '22', '28', '34', '49', '57', '67', '97', '115', '123', '143', '147', '151', '323', '379']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'stop_id'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'stop_id'},{'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': 'route'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'api_key'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'api_key'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '37', 'type': 'binary_operator', 'children': ['38', '47', '48'], 'value': '+'},{'id': '38', 'type': 'binary_operator', 'children': ['39', '43', '44'], 'value': '+'},{'id': '39', 'type': 'concatenated_string', 'children': ['40', '41', '42']},{'id': '40', 'type': 'string', 'children': [], 'value': "'https://api.transport.nsw.gov.au/v1/tp/departure_mon?'"},{'id': '41', 'type': 'string', 'children': [], 'value': "'outputFormat=rapidJSON&coordOutputFormat=EPSG%3A4326&'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'mode=direct&type_dm=stop&name_dm='"},{'id': '43', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'stop_id'},{'id': '47', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '48', 'type': 'string', 'children': [], 'value': "'&departureMonitorMacro=true&TfNSWDM=true&version=10.2.1.42'"},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '+'},{'id': '53', 'type': 'string', 'children': [], 'value': "'apikey '"},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'api_key'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '60', 'type': 'dictionary', 'children': ['61', '64']},{'id': '61', 'type': 'pair', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'Accept'"},{'id': '63', 'type': 'string', 'children': [], 'value': "'application/json'"},{'id': '64', 'type': 'pair', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': "'Authorization'"},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '67', 'type': 'try_statement', 'children': ['68', '84']},{'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': 'response'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '81']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '83', 'type': 'integer', 'children': [], 'value': '10'},{'id': '84', 'type': 'except_clause', 'children': ['85']},{'id': '85', 'type': 'block', 'children': ['86', '93']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': '"Network or Timeout error"'},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '97', 'type': 'if_statement', 'children': ['98', '103']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '102'], 'value': '!='},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '102', 'type': 'integer', 'children': [], 'value': '200'},{'id': '103', 'type': 'block', 'children': ['104', '111']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': '"Error with the request sent; check api key"'},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'try_statement', 'children': ['124', '129']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '128', 'type': 'string', 'children': [], 'value': "'stopEvents'"},{'id': '129', 'type': 'except_clause', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '131', 'type': 'block', 'children': ['132', '139']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'string', 'children': [], 'value': '"No stop events for this query"'},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'maxresults'},{'id': '146', 'type': 'integer', 'children': [], 'value': '1'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '150', 'type': 'list', 'children': [], 'value': '[]'},{'id': '151', 'type': 'if_statement', 'children': ['152', '157', '222', '291']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '156'], 'value': '!='},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '156', 'type': 'string', 'children': [], 'value': "''"},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'for_statement', 'children': ['159', '160', '169']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '168', 'type': 'string', 'children': [], 'value': "'stopEvents'"},{'id': '169', 'type': 'block', 'children': ['170', '184']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '173', 'type': 'subscript', 'children': ['174', '183']},{'id': '174', 'type': 'subscript', 'children': ['175', '182']},{'id': '175', 'type': 'subscript', 'children': ['176', '181']},{'id': '176', 'type': 'subscript', 'children': ['177', '180']},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '179', 'type': 'string', 'children': [], 'value': "'stopEvents'"},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '181', 'type': 'string', 'children': [], 'value': "'transportation'"},{'id': '182', 'type': 'string', 'children': [], 'value': "'destination'"},{'id': '183', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '184', 'type': 'if_statement', 'children': ['185', '190']},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': '=='},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '190', 'type': 'block', 'children': ['191', '201', '213']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'parseEvent'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '201', 'type': 'if_statement', 'children': ['202', '205']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': '!='},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '204', 'type': 'None', 'children': []},{'id': '205', 'type': 'block', 'children': ['206']},{'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': 'monitor'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '213', 'type': 'if_statement', 'children': ['214', '220']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '219'], 'value': '>='},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'maxresults'},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'break_statement', 'children': []},{'id': '222', 'type': 'elif_clause', 'children': ['223', '228']},{'id': '223', 'type': 'comparison_operator', 'children': ['224', '227'], 'value': '!='},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '227', 'type': 'string', 'children': [], 'value': "''"},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'for_statement', 'children': ['230', '231', '240']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '239', 'type': 'string', 'children': [], 'value': "'stopEvents'"},{'id': '240', 'type': 'block', 'children': ['241', '253']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '244', 'type': 'subscript', 'children': ['245', '252']},{'id': '245', 'type': 'subscript', 'children': ['246', '251']},{'id': '246', 'type': 'subscript', 'children': ['247', '250']},{'id': '247', 'type': 'subscript', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '249', 'type': 'string', 'children': [], 'value': "'stopEvents'"},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '251', 'type': 'string', 'children': [], 'value': "'transportation'"},{'id': '252', 'type': 'string', 'children': [], 'value': "'number'"},{'id': '253', 'type': 'if_statement', 'children': ['254', '259']},{'id': '254', 'type': 'comparison_operator', 'children': ['255', '256'], 'value': '=='},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'route'},{'id': '259', 'type': 'block', 'children': ['260', '270', '282']},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'parseEvent'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '270', 'type': 'if_statement', 'children': ['271', '274']},{'id': '271', 'type': 'comparison_operator', 'children': ['272', '273'], 'value': '!='},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '273', 'type': 'None', 'children': []},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '282', 'type': 'if_statement', 'children': ['283', '289']},{'id': '283', 'type': 'comparison_operator', 'children': ['284', '288'], 'value': '>='},{'id': '284', 'type': 'call', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'maxresults'},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'break_statement', 'children': []},{'id': '291', 'type': 'else_clause', 'children': ['292']},{'id': '292', 'type': 'block', 'children': ['293']},{'id': '293', 'type': 'for_statement', 'children': ['294', '295', '300']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '295', 'type': 'call', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '297', 'type': 'argument_list', 'children': ['298', '299']},{'id': '298', 'type': 'integer', 'children': [], 'value': '0'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'maxresults'},{'id': '300', 'type': 'block', 'children': ['301', '311']},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'assignment', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '304', 'type': 'call', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'parseEvent'},{'id': '308', 'type': 'argument_list', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '311', 'type': 'if_statement', 'children': ['312', '315']},{'id': '312', 'type': 'comparison_operator', 'children': ['313', '314'], 'value': '!='},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '314', 'type': 'None', 'children': []},{'id': '315', 'type': 'block', 'children': ['316']},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '323', 'type': 'if_statement', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '325', 'type': 'block', 'children': ['326']},{'id': '326', 'type': 'expression_statement', 'children': ['327']},{'id': '327', 'type': 'assignment', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '331', 'type': 'dictionary', 'children': ['332', '337', '344', '351', '358', '365', '372']},{'id': '332', 'type': 'pair', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'ATTR_STOP_ID'},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'stop_id'},{'id': '337', 'type': 'pair', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'ATTR_ROUTE'},{'id': '339', 'type': 'subscript', 'children': ['340', '343']},{'id': '340', 'type': 'subscript', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '342', 'type': 'integer', 'children': [], 'value': '0'},{'id': '343', 'type': 'integer', 'children': [], 'value': '0'},{'id': '344', 'type': 'pair', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'ATTR_DUE_IN'},{'id': '346', 'type': 'subscript', 'children': ['347', '350']},{'id': '347', 'type': 'subscript', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '349', 'type': 'integer', 'children': [], 'value': '0'},{'id': '350', 'type': 'integer', 'children': [], 'value': '1'},{'id': '351', 'type': 'pair', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'ATTR_DELAY'},{'id': '353', 'type': 'subscript', 'children': ['354', '357']},{'id': '354', 'type': 'subscript', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '356', 'type': 'integer', 'children': [], 'value': '0'},{'id': '357', 'type': 'integer', 'children': [], 'value': '2'},{'id': '358', 'type': 'pair', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'ATTR_REALTIME'},{'id': '360', 'type': 'subscript', 'children': ['361', '364']},{'id': '361', 'type': 'subscript', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '363', 'type': 'integer', 'children': [], 'value': '0'},{'id': '364', 'type': 'integer', 'children': [], 'value': '5'},{'id': '365', 'type': 'pair', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'ATTR_DESTINATION'},{'id': '367', 'type': 'subscript', 'children': ['368', '371']},{'id': '368', 'type': 'subscript', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '370', 'type': 'integer', 'children': [], 'value': '0'},{'id': '371', 'type': 'integer', 'children': [], 'value': '6'},{'id': '372', 'type': 'pair', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'ATTR_MODE'},{'id': '374', 'type': 'subscript', 'children': ['375', '378']},{'id': '375', 'type': 'subscript', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '377', 'type': 'integer', 'children': [], 'value': '0'},{'id': '378', 'type': 'integer', 'children': [], 'value': '7'},{'id': '379', 'type': 'return_statement', 'children': ['380']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'info'}
def get_departures(self, stop_id, route, destination, api_key): self.stop_id = stop_id self.route = route self.destination = destination self.api_key = api_key url = \ 'https://api.transport.nsw.gov.au/v1/tp/departure_mon?' \ 'outputFormat=rapidJSON&coordOutputFormat=EPSG%3A4326&' \ 'mode=direct&type_dm=stop&name_dm=' \ + self.stop_id \ + '&departureMonitorMacro=true&TfNSWDM=true&version=10.2.1.42' auth = 'apikey ' + self.api_key header = {'Accept': 'application/json', 'Authorization': auth} try: response = requests.get(url, headers=header, timeout=10) except: logger.warning("Network or Timeout error") return self.info if response.status_code != 200: logger.warning("Error with the request sent; check api key") return self.info result = response.json() try: result['stopEvents'] except KeyError: logger.warning("No stop events for this query") return self.info maxresults = 1 monitor = [] if self.destination != '': for i in range(len(result['stopEvents'])): destination = result['stopEvents'][i]['transportation']['destination']['name'] if destination == self.destination: event = self.parseEvent(result, i) if event != None: monitor.append(event) if len(monitor) >= maxresults: break elif self.route != '': for i in range(len(result['stopEvents'])): number = result['stopEvents'][i]['transportation']['number'] if number == self.route: event = self.parseEvent(result, i) if event != None: monitor.append(event) if len(monitor) >= maxresults: break else: for i in range(0, maxresults): event = self.parseEvent(result, i) if event != None: monitor.append(event) if monitor: self.info = { ATTR_STOP_ID: self.stop_id, ATTR_ROUTE: monitor[0][0], ATTR_DUE_IN: monitor[0][1], ATTR_DELAY: monitor[0][2], ATTR_REALTIME: monitor[0][5], ATTR_DESTINATION: monitor[0][6], ATTR_MODE: monitor[0][7] } return self.info
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pw'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key_pattern'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'user_pattern'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'strict_flag'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'user_flag'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'edit_subcommand'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'gen_subcommand'},{'id': '13', 'type': 'block', 'children': ['14', '33', '43', '73', '103', '112', '128', '138', '145', '172', '198']},{'id': '14', 'type': 'function_definition', 'children': ['15', '16', '19']},{'id': '15', 'type': 'function_name', 'children': [], 'value': 'handle_sigint'},{'id': '16', 'type': 'parameters', 'children': ['17']},{'id': '17', 'type': 'list_splat_pattern', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '19', 'type': 'block', 'children': ['20', '26']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'signal'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'signal'},{'id': '38', 'type': 'argument_list', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'signal'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'SIGINT'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'handle_sigint'},{'id': '43', 'type': 'if_statement', 'children': ['44', '45', '63']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'gen_subcommand'},{'id': '45', 'type': 'block', 'children': ['46', '56', '62']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '49', 'type': 'conditional_expression', 'children': ['50', '54', '55'], 'value': 'if'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key_pattern'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'key_pattern'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'generate_password'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '62', 'type': 'return_statement', 'children': []},{'id': '63', 'type': 'elif_clause', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'edit_subcommand'},{'id': '65', 'type': 'block', 'children': ['66', '72']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'launch_editor'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '72', 'type': 'return_statement', 'children': []},{'id': '73', 'type': 'if_statement', 'children': ['74', '83']},{'id': '74', 'type': 'not_operator', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '83', 'type': 'block', 'children': ['84', '96']},{'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': 'click'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '89', 'type': 'argument_list', 'children': ['90', '93']},{'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '%'},{'id': '91', 'type': 'string', 'children': [], 'value': '"error: password store not found at \'%s\'"'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '95', 'type': 'True', 'children': []},{'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': 'ctx'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'Store'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '112', 'type': 'if_statement', 'children': ['113', '115']},{'id': '113', 'type': 'not_operator', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'user_pattern'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '122']},{'id': '118', 'type': 'pattern_list', 'children': ['119', '120', '121']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'user_pattern'},{'id': '120', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'key_pattern'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'key_pattern'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'rpartition'},{'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', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'key_pattern'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'user_pattern'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '145', 'type': 'if_statement', 'children': ['146', '154']},{'id': '146', 'type': 'boolean_operator', 'children': ['147', '148'], 'value': 'and'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'strict_flag'},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '153'], 'value': '!='},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '153', 'type': 'integer', 'children': [], 'value': '1'},{'id': '154', 'type': 'block', 'children': ['155', '165']},{'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': 'click'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'string', 'children': [], 'value': '"error: multiple or no records found (but using --strict flag)"'},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '164', 'type': 'True', 'children': []},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'integer', 'children': [], 'value': '2'},{'id': '172', 'type': 'if_statement', 'children': ['173', '178']},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '=='},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'Mode'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'RAW'},{'id': '178', 'type': 'block', 'children': ['179', '197']},{'id': '179', 'type': 'for_statement', 'children': ['180', '181', '182']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'results'},{'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': 'click'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'conditional_expression', 'children': ['190', '193', '194'], 'value': 'if'},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'user_flag'},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '197', 'type': 'return_statement', 'children': []},{'id': '198', 'type': 'for_statement', 'children': ['199', '202', '206']},{'id': '199', 'type': 'pattern_list', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '206', 'type': 'block', 'children': ['207', '217', '234', '314', '380']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'highlight_match'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'key_pattern'},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '217', 'type': 'if_statement', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'augmented_assignment', 'children': ['224', '225'], 'value': '+='},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '227'], 'value': '+'},{'id': '226', 'type': 'string', 'children': [], 'value': '": "'},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'highlight_match'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'user_pattern'},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '234', 'type': 'if_statement', 'children': ['235', '243', '255']},{'id': '235', 'type': 'boolean_operator', 'children': ['236', '241'], 'value': 'and'},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': '=='},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'Mode'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'ECHO'},{'id': '241', 'type': 'not_operator', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'user_flag'},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'augmented_assignment', 'children': ['246', '247'], 'value': '+='},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '+'},{'id': '248', 'type': 'string', 'children': [], 'value': '" | "'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'style_password'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '255', 'type': 'elif_clause', 'children': ['256', '265']},{'id': '256', 'type': 'boolean_operator', 'children': ['257', '262'], 'value': 'and'},{'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': '=='},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'Mode'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'COPY'},{'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': '=='},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '264', 'type': 'integer', 'children': [], 'value': '0'},{'id': '265', 'type': 'block', 'children': ['266', '308']},{'id': '266', 'type': 'try_statement', 'children': ['267', '298']},{'id': '267', 'type': 'block', 'children': ['268', '271', '285']},{'id': '268', 'type': 'import_statement', 'children': ['269']},{'id': '269', 'type': 'dotted_name', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'pyperclip'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'pyperclip'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'conditional_expression', 'children': ['278', '281', '282'], 'value': 'if'},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'user_flag'},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'style_success'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'binary_operator', 'children': ['292', '293'], 'value': '%'},{'id': '292', 'type': 'string', 'children': [], 'value': '"*** %s COPIED TO CLIPBOARD ***"'},{'id': '293', 'type': '()', 'children': ['294']},{'id': '294', 'type': 'conditional_expression', 'children': ['295', '296', '297'], 'value': 'if'},{'id': '295', 'type': 'string', 'children': [], 'value': '"USERNAME"'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'user_flag'},{'id': '297', 'type': 'string', 'children': [], 'value': '"PASSWORD"'},{'id': '298', 'type': 'except_clause', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '300', 'type': 'block', 'children': ['301']},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'assignment', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'style_error'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'string', 'children': [], 'value': '\'*** PYTHON PACKAGE "PYPERCLIP" NOT FOUND ***\''},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'augmented_assignment', 'children': ['310', '311'], 'value': '+='},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '311', 'type': 'binary_operator', 'children': ['312', '313'], 'value': '+'},{'id': '312', 'type': 'string', 'children': [], 'value': '" | "'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '314', 'type': 'if_statement', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '318', 'type': 'block', 'children': ['319']},{'id': '319', 'type': 'if_statement', 'children': ['320', '323', '348']},{'id': '320', 'type': 'comparison_operator', 'children': ['321', '322'], 'value': '=='},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '322', 'type': 'integer', 'children': [], 'value': '0'},{'id': '323', 'type': 'block', 'children': ['324', '328']},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'augmented_assignment', 'children': ['326', '327'], 'value': '+='},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '327', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'augmented_assignment', 'children': ['330', '331'], 'value': '+='},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '331', 'type': 'call', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '335', 'type': 'generator_expression', 'children': ['336', '339']},{'id': '336', 'type': 'binary_operator', 'children': ['337', '338'], 'value': '+'},{'id': '337', 'type': 'string', 'children': [], 'value': '" "'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '339', 'type': 'for_in_clause', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '341', 'type': 'call', 'children': ['342', '347']},{'id': '342', 'type': 'attribute', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '347', 'type': 'argument_list', 'children': []},{'id': '348', 'type': 'else_clause', 'children': ['349']},{'id': '349', 'type': 'block', 'children': ['350', '360', '368']},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'assignment', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '353', 'type': 'call', 'children': ['354', '359']},{'id': '354', 'type': 'attribute', 'children': ['355', '358']},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'notes'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '359', 'type': 'argument_list', 'children': []},{'id': '360', 'type': 'expression_statement', 'children': ['361']},{'id': '361', 'type': 'augmented_assignment', 'children': ['362', '363'], 'value': '+='},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '363', 'type': 'binary_operator', 'children': ['364', '365'], 'value': '+'},{'id': '364', 'type': 'string', 'children': [], 'value': '" | "'},{'id': '365', 'type': 'subscript', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '367', 'type': 'integer', 'children': [], 'value': '0'},{'id': '368', 'type': 'if_statement', 'children': ['369', '375']},{'id': '369', 'type': 'comparison_operator', 'children': ['370', '374'], 'value': '>'},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '372', 'type': 'argument_list', 'children': ['373']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '374', 'type': 'integer', 'children': [], 'value': '1'},{'id': '375', 'type': 'block', 'children': ['376']},{'id': '376', 'type': 'expression_statement', 'children': ['377']},{'id': '377', 'type': 'augmented_assignment', 'children': ['378', '379'], 'value': '+='},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '379', 'type': 'string', 'children': [], 'value': '" (...)"'},{'id': '380', 'type': 'expression_statement', 'children': ['381']},{'id': '381', 'type': 'call', 'children': ['382', '385']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'line'}
def pw( ctx, key_pattern, user_pattern, mode, strict_flag, user_flag, file, edit_subcommand, gen_subcommand, ): def handle_sigint(*_): click.echo() ctx.exit(1) signal.signal(signal.SIGINT, handle_sigint) if gen_subcommand: length = int(key_pattern) if key_pattern else None generate_password(mode, length) return elif edit_subcommand: launch_editor(ctx, file) return if not os.path.exists(file): click.echo("error: password store not found at '%s'" % file, err=True) ctx.exit(1) store = Store.load(file) if not user_pattern: user_pattern, _, key_pattern = key_pattern.rpartition("@") results = store.search(key_pattern, user_pattern) results = list(results) if strict_flag and len(results) != 1: click.echo( "error: multiple or no records found (but using --strict flag)", err=True ) ctx.exit(2) if mode == Mode.RAW: for entry in results: click.echo(entry.user if user_flag else entry.password) return for idx, entry in enumerate(results): line = highlight_match(key_pattern, entry.key) if entry.user: line += ": " + highlight_match(user_pattern, entry.user) if mode == Mode.ECHO and not user_flag: line += " | " + style_password(entry.password) elif mode == Mode.COPY and idx == 0: try: import pyperclip pyperclip.copy(entry.user if user_flag else entry.password) result = style_success( "*** %s COPIED TO CLIPBOARD ***" % ("USERNAME" if user_flag else "PASSWORD") ) except ImportError: result = style_error('*** PYTHON PACKAGE "PYPERCLIP" NOT FOUND ***') line += " | " + result if entry.notes: if idx == 0: line += "\n" line += "\n".join(" " + line for line in entry.notes.splitlines()) else: lines = entry.notes.splitlines() line += " | " + lines[0] if len(lines) > 1: line += " (...)" click.echo(line)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'launch_editor'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '6', 'type': 'block', 'children': ['7', '18', '36', '66', '75', '101', '133', '142', '165', '178', '187', '211']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '10', 'type': 'call', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': '"PW_EDITOR"'},{'id': '18', 'type': 'if_statement', 'children': ['19', '21']},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '21', 'type': 'block', 'children': ['22', '29']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': '"error: no editor set in PW_EDITOR environment variables"'},{'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': 'ctx'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'integer', 'children': [], 'value': '1'},{'id': '36', 'type': 'if_statement', 'children': ['37', '46']},{'id': '37', 'type': 'not_operator', 'children': ['38']},{'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': 'os'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '46', 'type': 'block', 'children': ['47', '59']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '52', 'type': 'argument_list', 'children': ['53', '56']},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '%'},{'id': '54', 'type': 'string', 'children': [], 'value': '"error: password store not found at \'%s\'"'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '58', 'type': 'True', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'integer', 'children': [], 'value': '1'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'is_encrypted'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_gpg'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'is_encrypted'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '75', 'type': 'if_statement', 'children': ['76', '77', '87']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'is_encrypted'},{'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': 'original'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_gpg'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'decrypt'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'file'},{'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': 'original'},{'id': '92', 'type': 'call', 'children': ['93', '100']},{'id': '93', 'type': 'attribute', 'children': ['94', '99']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '98', 'type': 'string', 'children': [], 'value': '"rb"'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'if_statement', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'is_encrypted'},{'id': '103', 'type': 'block', 'children': ['104', '115']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'recipient'},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'string', 'children': [], 'value': '"PW_GPG_RECIPIENT"'},{'id': '115', 'type': 'if_statement', 'children': ['116', '118']},{'id': '116', 'type': 'not_operator', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'recipient'},{'id': '118', 'type': 'block', 'children': ['119', '126']},{'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': 'click'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'string', 'children': [], 'value': '"error: no recipient set in PW_GPG_RECIPIENT environment variables"'},{'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': 'ctx'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_gpg'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'unencrypted_ext'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'modified'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'edit'},{'id': '149', 'type': 'argument_list', 'children': ['150', '156', '159', '162']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'original'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'require_save'},{'id': '161', 'type': 'True', 'children': []},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '165', 'type': 'if_statement', 'children': ['166', '169']},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': 'is'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'modified'},{'id': '168', 'type': 'None', 'children': []},{'id': '169', 'type': 'block', 'children': ['170', '177']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': '"not modified"'},{'id': '177', 'type': 'return_statement', 'children': []},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'modified'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'modified'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '187', 'type': 'if_statement', 'children': ['188', '190']},{'id': '188', 'type': 'not_operator', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'is_encrypted'},{'id': '190', 'type': 'block', 'children': ['191', '210']},{'id': '191', 'type': 'with_statement', 'children': ['192', '202']},{'id': '192', 'type': 'with_clause', 'children': ['193']},{'id': '193', 'type': 'with_item', 'children': ['194']},{'id': '194', 'type': 'as_pattern', 'children': ['195', '200']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '197', 'type': 'argument_list', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '199', 'type': 'string', 'children': [], 'value': '"wb"'},{'id': '200', 'type': 'as_pattern_target', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'fp'},{'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': 'fp'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'modified'},{'id': '210', 'type': 'return_statement', 'children': []},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': '_gpg'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'encrypt'},{'id': '216', 'type': 'argument_list', 'children': ['217', '220', '223']},{'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'recipient'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'recipient'},{'id': '220', 'type': 'keyword_argument', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'dest_path'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '223', 'type': 'keyword_argument', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'modified'}
def launch_editor(ctx, file): editor = os.environ.get("PW_EDITOR") if not editor: click.echo("error: no editor set in PW_EDITOR environment variables") ctx.exit(1) if not os.path.exists(file): click.echo("error: password store not found at '%s'" % file, err=True) ctx.exit(1) is_encrypted = _gpg.is_encrypted(file) if is_encrypted: original = _gpg.decrypt(file) else: original = open(file, "rb").read() if is_encrypted: recipient = os.environ.get("PW_GPG_RECIPIENT") if not recipient: click.echo( "error: no recipient set in PW_GPG_RECIPIENT environment variables" ) ctx.exit(1) ext = _gpg.unencrypted_ext(file) modified = click.edit( original.decode("utf-8"), editor=editor, require_save=True, extension=ext ) if modified is None: click.echo("not modified") return modified = modified.encode("utf-8") if not is_encrypted: with open(file, "wb") as fp: fp.write(modified) return _gpg.encrypt(recipient=recipient, dest_path=file, content=modified)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fit'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sim_mat'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'D_len'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '7', 'type': 'block', 'children': ['8', '14', '166']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'min_energy'},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'inf'},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '20']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'integer', 'children': [], 'value': '3'},{'id': '20', 'type': 'block', 'children': ['21', '53', '57', '61', '151']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'inds'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '43', '49']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'argmin'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'list_comprehension', 'children': ['31', '40']},{'id': '31', 'type': 'call', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sim_mat'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'idy'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'idy'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'D_len'},{'id': '49', 'type': 'if_clause', 'children': ['50']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'in'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'idy'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sim_mat'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '56', 'type': 'list', 'children': [], 'value': '[]'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'for_statement', 'children': ['62', '63', '69']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'inds'},{'id': '69', 'type': 'block', 'children': ['70', '83', '91', '138', '142']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'indsi'},{'id': '73', 'type': 'subscript', 'children': ['74', '82']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '=='},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'inds'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '88']},{'id': '85', 'type': 'pattern_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'minind'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'min_value'},{'id': '88', 'type': 'expression_list', 'children': ['89', '90']},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'for_statement', 'children': ['92', '95', '99']},{'id': '92', 'type': 'pattern_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'idy'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'indsi'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'if_statement', 'children': ['101', '104']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'in'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'idy'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sim_mat'},{'id': '104', 'type': 'block', 'children': ['105', '109', '125']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'for_statement', 'children': ['110', '111', '112']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'indsi'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'augmented_assignment', 'children': ['115', '116'], 'value': '+='},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '116', 'type': 'call', 'children': ['117', '122']},{'id': '117', 'type': 'attribute', 'children': ['118', '121']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'sim_mat'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'idy'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '124', 'type': 'integer', 'children': [], 'value': '0'},{'id': '125', 'type': 'if_statement', 'children': ['126', '129']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': '<'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'min_value'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '135']},{'id': '132', 'type': 'pattern_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'minind'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'min_value'},{'id': '135', 'type': 'expression_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'augmented_assignment', 'children': ['140', '141'], 'value': '+='},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'min_value'},{'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': 'cidx'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'indsi'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'minind'},{'id': '151', 'type': 'if_statement', 'children': ['152', '155']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': '<'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'min_energy'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '162']},{'id': '158', 'type': 'pattern_list', 'children': ['159', '160', '161']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'min_energy'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'inds_min'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'cidx_min'},{'id': '162', 'type': 'expression_list', 'children': ['163', '164', '165']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'inds'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'cidx'},{'id': '166', 'type': 'return_statement', 'children': ['167']},{'id': '167', 'type': 'expression_list', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'inds_min'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'cidx_min'}
def fit(sim_mat, D_len, cidx): min_energy = np.inf for j in range(3): inds = [np.argmin([sim_mat[idy].get(idx, 0) for idx in cidx]) for idy in range(D_len) if idy in sim_mat] cidx = [] energy = 0 for i in np.unique(inds): indsi = np.where(inds == i)[0] minind, min_value = 0, 0 for index, idy in enumerate(indsi): if idy in sim_mat: value = 0 for idx in indsi: value += sim_mat[idy].get(idx, 0) if value < min_value: minind, min_value = index, value energy += min_value cidx.append(indsi[minind]) if energy < min_energy: min_energy, inds_min, cidx_min = energy, inds, cidx return inds_min, cidx_min
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'authenticate'},{'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': 'remote_user'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '18', '24', '28', '37', '283']},{'id': '10', 'type': 'if_statement', 'children': ['11', '13']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'remote_user'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'remote_user'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '18', 'type': 'if_statement', 'children': ['19', '21']},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'remote_user'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'clean_username'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'remote_user'},{'id': '37', 'type': 'try_statement', 'children': ['38', '176']},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'if_statement', 'children': ['40', '43', '155']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'create_unknown_user'},{'id': '43', 'type': 'block', 'children': ['44', '48', '113', '135']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '47', 'type': 'dictionary', 'children': []},{'id': '48', 'type': 'if_statement', 'children': ['49', '54']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '54', 'type': 'block', 'children': ['55', '59', '89']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'session_data'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'},{'id': '61', 'type': 'string', 'children': [], 'value': "'full_name'"},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'session_data'},{'id': '63', 'type': 'block', 'children': ['64', '76']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '70']},{'id': '66', 'type': 'pattern_list', 'children': ['67', '68', '69']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'first_name'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'last_name'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'full_name_natural_split'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'session_data'},{'id': '75', 'type': 'string', 'children': [], 'value': "'full_name'"},{'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': 'defaults'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'dictionary', 'children': ['83', '86']},{'id': '83', 'type': 'pair', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': "'first_name'"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'first_name'},{'id': '86', 'type': 'pair', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': "'last_name'"},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'last_name'},{'id': '89', 'type': 'for_statement', 'children': ['90', '91', '95']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '91', 'type': 'tuple', 'children': ['92', '93', '94']},{'id': '92', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '93', 'type': 'string', 'children': [], 'value': "'first_name'"},{'id': '94', 'type': 'string', 'children': [], 'value': "'last_name'"},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'if_statement', 'children': ['97', '100']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'in'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'session_data'},{'id': '100', 'type': 'block', 'children': ['101']},{'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': 'defaults'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'dictionary', 'children': ['108']},{'id': '108', 'type': 'pair', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'session_data'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '118']},{'id': '115', 'type': 'pattern_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'created'},{'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': 'UserModel'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_default_manager'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'get_or_create'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'dictionary_splat', 'children': ['126']},{'id': '126', 'type': 'dictionary', 'children': ['127', '132']},{'id': '127', 'type': 'pair', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'UserModel'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'USERNAME_FIELD'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '132', 'type': 'pair', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': "'defaults'"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '135', 'type': 'if_statement', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'created'},{'id': '137', 'type': 'block', 'children': ['138', '146']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'string', 'children': [], 'value': '"created user \'%s\' in database."'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'user'},{'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': 'configure_user'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '155', 'type': 'else_clause', 'children': ['156']},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'try_statement', 'children': ['158', '170']},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'user'},{'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': 'UserModel'},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_default_manager'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'get_by_natural_key'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '170', 'type': 'except_clause', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'UserModel'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'DoesNotExist'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'pass_statement', 'children': []},{'id': '176', 'type': 'except_clause', 'children': ['177', '181']},{'id': '177', 'type': 'as_pattern', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'DatabaseError'},{'id': '179', 'type': 'as_pattern_target', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '181', 'type': 'block', 'children': ['182', '190', '237', '260', '273']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'string', 'children': [], 'value': '"User table missing from database? (err:%s)"'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '190', 'type': 'for_statement', 'children': ['191', '192', '200']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'itervalues'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '200', 'type': 'block', 'children': ['201', '215']},{'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': 'LOGGER'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208', '209', '212']},{'id': '207', 'type': 'string', 'children': [], 'value': '"match %s with User(id=%d, username=%s)"'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '215', 'type': 'if_statement', 'children': ['216', '221']},{'id': '216', 'type': 'comparison_operator', 'children': ['217', '220'], 'value': '=='},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '221', 'type': 'block', 'children': ['222', '235']},{'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', '229', '232']},{'id': '228', 'type': 'string', 'children': [], 'value': '"found %d %s"'},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '235', 'type': 'return_statement', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'UserModel'},{'id': '242', 'type': 'argument_list', 'children': ['243', '257']},{'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'randint'},{'id': '249', 'type': 'argument_list', 'children': ['250', '251']},{'id': '250', 'type': 'integer', 'children': [], 'value': '1'},{'id': '251', 'type': 'binary_operator', 'children': ['252', '256'], 'value': '-'},{'id': '252', 'type': '()', 'children': ['253']},{'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '<<'},{'id': '254', 'type': 'integer', 'children': [], 'value': '1'},{'id': '255', 'type': 'integer', 'children': [], 'value': '32'},{'id': '256', 'type': 'integer', 'children': [], 'value': '1'},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'username'},{'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', '267', '270']},{'id': '266', 'type': 'string', 'children': [], 'value': '"add User(id=%d, username=%s) to cache."'},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '282']},{'id': '275', 'type': 'subscript', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '283', 'type': 'return_statement', 'children': ['284']},{'id': '284', 'type': 'conditional_expression', 'children': ['285', '286', '292'], 'value': 'if'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'user_can_authenticate'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '292', 'type': 'None', 'children': []}
def authenticate(self, request, remote_user=None): if not remote_user: remote_user = request if not remote_user: return None user = None username = self.clean_username(remote_user) try: if self.create_unknown_user: defaults = {} if isinstance(request, dict): session_data = request if 'full_name' in session_data: first_name, _, last_name = full_name_natural_split( session_data['full_name']) defaults.update({ 'first_name': first_name, 'last_name': last_name }) for key in ('email', 'first_name', 'last_name'): if key in session_data: defaults.update({key: session_data[key]}) user, created = UserModel._default_manager.get_or_create(**{ UserModel.USERNAME_FIELD: username, 'defaults': defaults, }) if created: LOGGER.debug("created user '%s' in database.", username) user = self.configure_user(user) else: try: user = UserModel._default_manager.get_by_natural_key( username) except UserModel.DoesNotExist: pass except DatabaseError as err: LOGGER.debug("User table missing from database? (err:%s)", err) for user in six.itervalues(self.users): LOGGER.debug("match %s with User(id=%d, username=%s)", username, user.id, user.username) if user.username == username: LOGGER.debug("found %d %s", user.id, user.username) return user user = UserModel( id=random.randint(1, (1 << 32) - 1), username=username) LOGGER.debug("add User(id=%d, username=%s) to cache.", user.id, user.username) self.users[user.id] = user return user if self.user_can_authenticate(user) else None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'bc2pg'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'db_url'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'max_workers'},{'id': '13', 'type': 'block', 'children': ['14', '23', '42', '50', '58', '67', '93', '111']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'bcdata'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'validate_name'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '28']},{'id': '25', 'type': 'pattern_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'src_schema'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'src_table'},{'id': '28', 'type': 'list_comprehension', 'children': ['29', '34']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'for_in_clause', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'string', 'children': [], 'value': '"."'},{'id': '42', 'type': 'if_statement', 'children': ['43', '45']},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'schema'},{'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': 'schema'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'src_schema'},{'id': '50', 'type': 'if_statement', 'children': ['51', '53']},{'id': '51', 'type': 'not_operator', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'table'},{'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': 'table'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'src_table'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'pgdata'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'db_url'},{'id': '67', 'type': 'if_statement', 'children': ['68', '73']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'not'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'schemas'},{'id': '73', 'type': 'block', 'children': ['74', '86']},{'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': 'click'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': '"Schema {} does not exist, creating it"'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'create_schema'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'param_dicts'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'bcdata'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'define_request'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102', '105', '108']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'pagesize'},{'id': '111', 'type': 'try_statement', 'children': ['112', '377']},{'id': '112', 'type': 'block', 'children': ['113', '125', '135', '142', '170', '217', '359']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '118', 'type': 'argument_list', 'children': ['119', '122']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'param_dicts'},{'id': '121', 'type': 'integer', 'children': [], 'value': '0'},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'doseq'},{'id': '124', 'type': 'True', 'children': []},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '128', 'type': 'binary_operator', 'children': ['129', '134'], 'value': '+'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '133'], 'value': '+'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'bcdata'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'WFS_URL'},{'id': '133', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'parse_db_url'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'db_url'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'db_string'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': '"PG:host={h} user={u} dbname={db} password={pwd}"'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '149', 'type': 'argument_list', 'children': ['150', '155', '160', '165']},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '154', 'type': 'string', 'children': [], 'value': '"host"'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '159', 'type': 'string', 'children': [], 'value': '"user"'},{'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '164', 'type': 'string', 'children': [], 'value': '"database"'},{'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'pwd'},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '169', 'type': 'string', 'children': [], 'value': '"password"'},{'id': '170', 'type': 'if_statement', 'children': ['171', '173']},{'id': '171', 'type': 'not_operator', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '173', 'type': 'block', 'children': ['174', '198', '210']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '177', 'type': 'list', 'children': ['178', '179', '180', '181', '182', '188', '189', '190', '191', '192', '193', '194', '195', '196', '197'], 'value': '[\n "ogr2ogr",\n "-lco",\n "OVERWRITE=YES",\n "-lco",\n "SCHEMA={}".format(schema),\n "-lco",\n "GEOMETRY_NAME=geom",\n "-f",\n "PostgreSQL",\n db_string,\n "-t_srs",\n "EPSG:3005",\n "-nln",\n table,\n url,\n ]'},{'id': '178', 'type': 'string', 'children': [], 'value': '"ogr2ogr"'},{'id': '179', 'type': 'string', 'children': [], 'value': '"-lco"'},{'id': '180', 'type': 'string', 'children': [], 'value': '"OVERWRITE=YES"'},{'id': '181', 'type': 'string', 'children': [], 'value': '"-lco"'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'string', 'children': [], 'value': '"SCHEMA={}"'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '188', 'type': 'string', 'children': [], 'value': '"-lco"'},{'id': '189', 'type': 'string', 'children': [], 'value': '"GEOMETRY_NAME=geom"'},{'id': '190', 'type': 'string', 'children': [], 'value': '"-f"'},{'id': '191', 'type': 'string', 'children': [], 'value': '"PostgreSQL"'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'db_string'},{'id': '193', 'type': 'string', 'children': [], 'value': '"-t_srs"'},{'id': '194', 'type': 'string', 'children': [], 'value': '"EPSG:3005"'},{'id': '195', 'type': 'string', 'children': [], 'value': '"-nln"'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'string', 'children': [], 'value': '" "'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '217', 'type': 'if_statement', 'children': ['218', '226']},{'id': '218', 'type': 'boolean_operator', 'children': ['219', '225'], 'value': 'or'},{'id': '219', 'type': 'comparison_operator', 'children': ['220', '224'], 'value': '>'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'param_dicts'},{'id': '224', 'type': 'integer', 'children': [], 'value': '1'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '226', 'type': 'block', 'children': ['227', '240', '244', '303', '310']},{'id': '227', 'type': 'if_statement', 'children': ['228', '229', '234']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '233', 'type': 'integer', 'children': [], 'value': '0'},{'id': '234', 'type': 'else_clause', 'children': ['235']},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '239', 'type': 'integer', 'children': [], 'value': '1'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '243', 'type': 'list', 'children': [], 'value': '[]'},{'id': '244', 'type': 'for_statement', 'children': ['245', '248', '256']},{'id': '245', 'type': 'pattern_list', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'paramdict'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'subscript', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'param_dicts'},{'id': '253', 'type': 'slice', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '255', 'type': 'colon', 'children': []},{'id': '256', 'type': 'block', 'children': ['257', '267', '277', '296']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '262', 'type': 'argument_list', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'paramdict'},{'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'doseq'},{'id': '266', 'type': 'True', 'children': []},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '270', 'type': 'binary_operator', 'children': ['271', '276'], 'value': '+'},{'id': '271', 'type': 'binary_operator', 'children': ['272', '275'], 'value': '+'},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'bcdata'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'WFS_URL'},{'id': '275', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '280', 'type': 'list', 'children': ['281', '282', '283', '284', '285', '286', '291', '292', '293', '294', '295'], 'value': '[\n "ogr2ogr",\n "-update",\n "-append",\n "-f",\n "PostgreSQL",\n db_string + " active_schema=" + schema,\n "-t_srs",\n "EPSG:3005",\n "-nln",\n table,\n url,\n ]'},{'id': '281', 'type': 'string', 'children': [], 'value': '"ogr2ogr"'},{'id': '282', 'type': 'string', 'children': [], 'value': '"-update"'},{'id': '283', 'type': 'string', 'children': [], 'value': '"-append"'},{'id': '284', 'type': 'string', 'children': [], 'value': '"-f"'},{'id': '285', 'type': 'string', 'children': [], 'value': '"PostgreSQL"'},{'id': '286', 'type': 'binary_operator', 'children': ['287', '290'], 'value': '+'},{'id': '287', 'type': 'binary_operator', 'children': ['288', '289'], 'value': '+'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'db_string'},{'id': '289', 'type': 'string', 'children': [], 'value': '" active_schema="'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '291', 'type': 'string', 'children': [], 'value': '"-t_srs"'},{'id': '292', 'type': 'string', 'children': [], 'value': '"EPSG:3005"'},{'id': '293', 'type': 'string', 'children': [], 'value': '"-nln"'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'url'},{'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': 'commands'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'assignment', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'Pool'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'max_workers'},{'id': '310', 'type': 'with_statement', 'children': ['311', '337']},{'id': '311', 'type': 'with_clause', 'children': ['312']},{'id': '312', 'type': 'with_item', 'children': ['313']},{'id': '313', 'type': 'as_pattern', 'children': ['314', '335']},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'progressbar'},{'id': '318', 'type': 'argument_list', 'children': ['319', '329']},{'id': '319', 'type': 'call', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '323', 'type': 'argument_list', 'children': ['324', '328']},{'id': '324', 'type': 'call', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '326', 'type': 'argument_list', 'children': ['327']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '329', 'type': 'keyword_argument', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '331', 'type': 'call', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '333', 'type': 'argument_list', 'children': ['334']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'param_dicts'},{'id': '335', 'type': 'as_pattern_target', 'children': ['336']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'bar'},{'id': '337', 'type': 'block', 'children': ['338']},{'id': '338', 'type': 'for_statement', 'children': ['339', '340', '341']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'returncode'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'bar'},{'id': '341', 'type': 'block', 'children': ['342']},{'id': '342', 'type': 'if_statement', 'children': ['343', '346']},{'id': '343', 'type': 'comparison_operator', 'children': ['344', '345'], 'value': '!='},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'returncode'},{'id': '345', 'type': 'integer', 'children': [], 'value': '0'},{'id': '346', 'type': 'block', 'children': ['347']},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'call', 'children': ['349', '352']},{'id': '349', 'type': 'attribute', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '352', 'type': 'argument_list', 'children': ['353']},{'id': '353', 'type': 'call', 'children': ['354', '357']},{'id': '354', 'type': 'attribute', 'children': ['355', '356']},{'id': '355', 'type': 'string', 'children': [], 'value': '"Command failed: {}"'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '357', 'type': 'argument_list', 'children': ['358']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'returncode'},{'id': '359', 'type': 'expression_statement', 'children': ['360']},{'id': '360', 'type': 'call', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'string', 'children': [], 'value': '"Load of {} to {} in {} complete"'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '369', 'type': 'argument_list', 'children': ['370', '371', '376']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '371', 'type': 'binary_operator', 'children': ['372', '375'], 'value': '+'},{'id': '372', 'type': 'binary_operator', 'children': ['373', '374'], 'value': '+'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '374', 'type': 'string', 'children': [], 'value': '"."'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'db_url'},{'id': '377', 'type': 'except_clause', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '379', 'type': 'block', 'children': ['380', '387']},{'id': '380', 'type': 'expression_statement', 'children': ['381']},{'id': '381', 'type': 'call', 'children': ['382', '385']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'string', 'children': [], 'value': '"Data load failed"'},{'id': '387', 'type': 'raise_statement', 'children': ['388']},{'id': '388', 'type': 'call', 'children': ['389', '392']},{'id': '389', 'type': 'attribute', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'Abort'},{'id': '392', 'type': 'argument_list', 'children': []}
def bc2pg(dataset, db_url, table, schema, query, append, pagesize, sortby, max_workers): src = bcdata.validate_name(dataset) src_schema, src_table = [i.lower() for i in src.split(".")] if not schema: schema = src_schema if not table: table = src_table conn = pgdata.connect(db_url) if schema not in conn.schemas: click.echo("Schema {} does not exist, creating it".format(schema)) conn.create_schema(schema) param_dicts = bcdata.define_request( dataset, query=query, sortby=sortby, pagesize=pagesize ) try: payload = urlencode(param_dicts[0], doseq=True) url = bcdata.WFS_URL + "?" + payload db = parse_db_url(db_url) db_string = "PG:host={h} user={u} dbname={db} password={pwd}".format( h=db["host"], u=db["user"], db=db["database"], pwd=db["password"] ) if not append: command = [ "ogr2ogr", "-lco", "OVERWRITE=YES", "-lco", "SCHEMA={}".format(schema), "-lco", "GEOMETRY_NAME=geom", "-f", "PostgreSQL", db_string, "-t_srs", "EPSG:3005", "-nln", table, url, ] click.echo(" ".join(command)) subprocess.run(command) if len(param_dicts) > 1 or append: if append: idx = 0 else: idx = 1 commands = [] for chunk, paramdict in enumerate(param_dicts[idx:]): payload = urlencode(paramdict, doseq=True) url = bcdata.WFS_URL + "?" + payload command = [ "ogr2ogr", "-update", "-append", "-f", "PostgreSQL", db_string + " active_schema=" + schema, "-t_srs", "EPSG:3005", "-nln", table, url, ] commands.append(command) pool = Pool(max_workers) with click.progressbar( pool.imap(partial(call), commands), length=len(param_dicts) ) as bar: for returncode in bar: if returncode != 0: click.echo("Command failed: {}".format(returncode)) click.echo( "Load of {} to {} in {} complete".format(src, schema + "." + table, db_url) ) except Exception: click.echo("Data load failed") raise click.Abort()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__parseFormat'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'fps'},{'id': '9', 'type': 'integer', 'children': [], 'value': '25'},{'id': '10', 'type': 'block', 'children': ['11', '13', '17', '21']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': "'''Actual parser. Please note that time_to is not required to process as not all subtitles\n provide it.'''"},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'headerFound'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'subSection'},{'id': '20', 'type': 'string', 'children': [], 'value': "''"},{'id': '21', 'type': 'for_statement', 'children': ['22', '25', '29']},{'id': '22', 'type': 'pattern_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'lineNo'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '29', 'type': 'block', 'children': ['30', '40', '58', '69']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'line'},{'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': '_initialLinePrepare'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'lineNo'},{'id': '40', 'type': 'if_statement', 'children': ['41', '56']},{'id': '41', 'type': 'boolean_operator', 'children': ['42', '51'], 'value': 'and'},{'id': '42', 'type': 'boolean_operator', 'children': ['43', '47'], 'value': 'and'},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'WITH_HEADER'},{'id': '47', 'type': 'not_operator', 'children': ['48']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_formatFound'},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '>'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'lineNo'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_maxFmtSearch'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'return_statement', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'subSection'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "''"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'list', 'children': ['67', '68'], 'value': '[subSection, line]'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'subSection'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '69', 'type': 'if_statement', 'children': ['70', '76', '114']},{'id': '70', 'type': 'boolean_operator', 'children': ['71', '74'], 'value': 'and'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'WITH_HEADER'},{'id': '74', 'type': 'not_operator', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'headerFound'},{'id': '76', 'type': 'block', 'children': ['77', '85', '101']},{'id': '77', 'type': 'if_statement', 'children': ['78', '83']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '>'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'lineNo'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_maxHeaderLen'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'return_statement', 'children': []},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'headerFound'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'addHeaderInfo'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'subSection'},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_subtitles'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'if_statement', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'headerFound'},{'id': '103', 'type': 'block', 'children': ['104', '110']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_formatFound'},{'id': '109', 'type': 'True', 'children': []},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'subSection'},{'id': '113', 'type': 'string', 'children': [], 'value': "''"},{'id': '114', 'type': 'elif_clause', 'children': ['115', '131']},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '122'], 'value': 'or'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'subtitleEnds'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '127'], 'value': '=='},{'id': '123', 'type': '()', 'children': ['124']},{'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '+'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'lineNo'},{'id': '126', 'type': 'integer', 'children': [], 'value': '1'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '131', 'type': 'block', 'children': ['132', '142', '183', '235']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'subtitle'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'createSubtitle'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'fps'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'subSection'},{'id': '142', 'type': 'if_statement', 'children': ['143', '146']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'is'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'subtitle'},{'id': '145', 'type': 'None', 'children': []},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'if_statement', 'children': ['148', '154', '160', '180']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'in'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'subSection'},{'id': '150', 'type': 'tuple', 'children': ['151', '152', '153']},{'id': '151', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '152', 'type': 'string', 'children': [], 'value': "'\\r\\n'"},{'id': '153', 'type': 'string', 'children': [], 'value': "'\\r'"},{'id': '154', 'type': 'block', 'children': ['155', '159']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'subSection'},{'id': '158', 'type': 'string', 'children': [], 'value': "''"},{'id': '159', 'type': 'continue_statement', 'children': []},{'id': '160', 'type': 'elif_clause', 'children': ['161', '170']},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '169'], 'value': '>'},{'id': '162', 'type': 'call', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_subtitles'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '168', 'type': 'argument_list', 'children': []},{'id': '169', 'type': 'integer', 'children': [], 'value': '0'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'raise_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'SubParsingError'},{'id': '174', 'type': 'argument_list', 'children': ['175', '179']},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'string', 'children': [], 'value': '"Parsing error"'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'lineNo'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'return_statement', 'children': []},{'id': '183', 'type': 'if_statement', 'children': ['184', '191', '221', '232']},{'id': '184', 'type': 'boolean_operator', 'children': ['185', '188'], 'value': 'and'},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'subtitle'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'subtitle'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '191', 'type': 'block', 'children': ['192', '198']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '196', 'type': 'identifier', 'children': [], 'value': '_formatFound'},{'id': '197', 'type': 'True', 'children': []},{'id': '198', 'type': 'try_statement', 'children': ['199', '209']},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '207']},{'id': '202', 'type': 'attribute', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '205', 'type': 'identifier', 'children': [], 'value': '_subtitles'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'subtitle'},{'id': '209', 'type': 'except_clause', 'children': ['210', '214']},{'id': '210', 'type': 'as_pattern', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'SubException'},{'id': '212', 'type': 'as_pattern_target', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'raise_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'SubParsingError'},{'id': '218', 'type': 'argument_list', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'lineNo'},{'id': '221', 'type': 'elif_clause', 'children': ['222', '230']},{'id': '222', 'type': 'boolean_operator', 'children': ['223', '226'], 'value': 'and'},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'subtitle'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '226', 'type': 'not_operator', 'children': ['227']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'subtitle'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'pass_statement', 'children': []},{'id': '232', 'type': 'else_clause', 'children': ['233']},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'return_statement', 'children': []},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'subSection'},{'id': '238', 'type': 'string', 'children': [], 'value': "''"}
def __parseFormat(self, fmt, content, fps = 25): '''Actual parser. Please note that time_to is not required to process as not all subtitles provide it.''' headerFound = False subSection = '' for lineNo, line in enumerate(content): line = self._initialLinePrepare(line, lineNo) if not fmt.WITH_HEADER and not self._formatFound and lineNo > self._maxFmtSearch: return subSection = ''.join([subSection, line]) if fmt.WITH_HEADER and not headerFound: if lineNo > self._maxHeaderLen: return headerFound = fmt.addHeaderInfo(subSection, self._subtitles.header()) if headerFound: self._formatFound = True subSection = '' elif fmt.subtitleEnds(line) or (lineNo + 1) == len(content): subtitle = fmt.createSubtitle(fps, subSection) if subtitle is None: if subSection in ('\n', '\r\n', '\r'): subSection = '' continue elif self._subtitles.size() > 0: raise SubParsingError(_("Parsing error"), lineNo) else: return if subtitle.start and subtitle.text: self._formatFound = True try: self._subtitles.append(subtitle) except SubException as msg: raise SubParsingError(msg, lineNo) elif subtitle.start and not subtitle.text: pass else: return subSection = ''
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_json'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'space'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'rel_path'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'extra_params'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'get_all'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '37', '45', '57', '82', '146']},{'id': '19', 'type': 'if_statement', 'children': ['20', '29']},{'id': '20', 'type': 'boolean_operator', 'children': ['21', '24'], 'value': 'and'},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'space'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'not'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '26', 'type': 'tuple', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'Space'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'Event'},{'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': 'Exception'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'concatenated_string', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': "'In general, `API._get_json` should always '"},{'id': '36', 'type': 'string', 'children': [], 'value': "'be called with a `space` argument.'"},{'id': '37', 'type': 'if_statement', 'children': ['38', '40']},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'extra_params'},{'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': 'extra_params'},{'id': '44', 'type': 'dictionary', 'children': []},{'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': 'extra_params'},{'id': '49', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'extra_params'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '56', 'type': 'integer', 'children': [], 'value': '1'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'{0}/{1}/{2}.json?{3}'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '64', 'type': 'argument_list', 'children': ['65', '68', '71', '76']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'API_ROOT_PATH'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'API_VERSION'},{'id': '71', 'type': 'boolean_operator', 'children': ['72', '73'], 'value': 'or'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'rel_path'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'rel_path'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'urllib'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'extra_params'},{'id': '82', 'type': 'if_statement', 'children': ['83', '92', '101']},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '87'], 'value': 'and'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'cache_responses'},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'in'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '96', 'type': 'subscript', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '101', 'type': 'else_clause', 'children': ['102']},{'id': '102', 'type': 'block', 'children': ['103', '117', '133']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '106', 'type': 'dictionary', 'children': ['107', '112']},{'id': '107', 'type': 'pair', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'X-Api-Key'"},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '112', 'type': 'pair', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': "'X-Api-Secret'"},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'secret'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'response'},{'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': 'session'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '126', 'type': 'argument_list', 'children': ['127', '130']},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '133', 'type': 'if_statement', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'cache_responses'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '145']},{'id': '140', 'type': 'subscript', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '146', 'type': 'if_statement', 'children': ['147', '152', '253', '262']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '151'], 'value': '=='},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '151', 'type': 'integer', 'children': [], 'value': '200'},{'id': '152', 'type': 'block', 'children': ['153', '157', '165', '200', '210', '251']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '156', 'type': 'list', 'children': [], 'value': '[]'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'json_response'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'for_statement', 'children': ['166', '167', '168']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'json_response'},{'id': '168', 'type': 'block', 'children': ['169', '178', '184', '193']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '184', 'type': 'if_statement', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'space'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'space'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'space'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'extra_params'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209']},{'id': '208', 'type': 'string', 'children': [], 'value': "'per_page'"},{'id': '209', 'type': 'None', 'children': []},{'id': '210', 'type': 'if_statement', 'children': ['211', '227']},{'id': '211', 'type': '()', 'children': ['212']},{'id': '212', 'type': 'boolean_operator', 'children': ['213', '221'], 'value': 'and'},{'id': '213', 'type': 'boolean_operator', 'children': ['214', '217'], 'value': 'and'},{'id': '214', 'type': 'boolean_operator', 'children': ['215', '216'], 'value': 'and'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'get_all'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'json_response'},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '223'], 'value': '=='},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'json_response'},{'id': '227', 'type': 'block', 'children': ['228', '234']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'augmented_assignment', 'children': ['230', '233'], 'value': '+='},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'extra_params'},{'id': '232', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '233', 'type': 'integer', 'children': [], 'value': '1'},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '237', 'type': 'binary_operator', 'children': ['238', '239'], 'value': '+'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '242', 'type': 'identifier', 'children': [], 'value': '_get_json'},{'id': '243', 'type': 'argument_list', 'children': ['244', '245', '246', '247', '248']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'space'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'rel_path'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'extra_params'},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'get_all'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'get_all'},{'id': '251', 'type': 'return_statement', 'children': ['252']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '253', 'type': 'elif_clause', 'children': ['254', '259']},{'id': '254', 'type': 'comparison_operator', 'children': ['255', '258'], 'value': '=='},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '258', 'type': 'integer', 'children': [], 'value': '204'},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'return_statement', 'children': ['261']},{'id': '261', 'type': 'list', 'children': [], 'value': '[]'},{'id': '262', 'type': 'else_clause', 'children': ['263']},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'raise_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'string', 'children': [], 'value': '\'Code {0} returned from `{1}`. Response text: "{2}".\''},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '272', 'type': 'argument_list', 'children': ['273', '276', '277']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'text'}
def _get_json(self, model, space=None, rel_path=None, extra_params=None, get_all=None): if space is None and model not in (Space, Event): raise Exception( 'In general, `API._get_json` should always ' 'be called with a `space` argument.' ) if not extra_params: extra_params = {} extra_params['page'] = extra_params.get('page', 1) url = '{0}/{1}/{2}.json?{3}'.format( settings.API_ROOT_PATH, settings.API_VERSION, rel_path or model.rel_path, urllib.urlencode(extra_params), ) if self.cache_responses and url in self.cache: response = self.cache[url] else: headers = { 'X-Api-Key': self.key, 'X-Api-Secret': self.secret, } response = self.session.get(url=url, headers=headers) if self.cache_responses: self.cache[url] = response if response.status_code == 200: results = [] json_response = response.json() for obj in json_response: instance = model(data=obj) instance.api = self if space: instance.space = space results.append(instance) per_page = extra_params.get('per_page', None) if ( get_all and per_page and len(json_response) and per_page == len(json_response) ): extra_params['page'] += 1 results = results + self._get_json(model, space, rel_path, extra_params, get_all=get_all) return results elif response.status_code == 204: return [] else: raise Exception( 'Code {0} returned from `{1}`. Response text: "{2}".'.format( response.status_code, url, response.text ) )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_config'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '14', '24', '34', '44', '72', '76', '96', '121', '125', '383']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'configure_logging'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': "'prefix'"},{'id': '23', 'type': 'string', 'children': [], 'value': "'etc'"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "'verbose'"},{'id': '33', 'type': 'False', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "'location'"},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'passphrase'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'passphrase'"},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'getenv'},{'id': '57', 'type': 'argument_list', 'children': ['58', '65']},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '%'},{'id': '59', 'type': 'string', 'children': [], 'value': '"%s_SETTINGS_CRYPT_KEY"'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'getenv'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': '"SETTINGS_CRYPT_KEY"'},{'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': 'confnames'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '76', 'type': 'if_statement', 'children': ['77', '79']},{'id': '77', 'type': 'not_operator', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'getenv'},{'id': '87', 'type': 'argument_list', 'children': ['88', '95']},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '%'},{'id': '89', 'type': 'string', 'children': [], 'value': '"%s_SETTINGS_LOCATION"'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'None', 'children': []},{'id': '96', 'type': 'if_statement', 'children': ['97', '99']},{'id': '97', 'type': 'not_operator', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '99', 'type': 'block', 'children': ['100', '110']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'getenv'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': '"SETTINGS_LOCATION"'},{'id': '109', 'type': 'None', 'children': []},{'id': '110', 'type': 'if_statement', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '%'},{'id': '117', 'type': 'string', 'children': [], 'value': '"%s/%s"'},{'id': '118', 'type': 'tuple', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '124', 'type': 'dictionary', 'children': []},{'id': '125', 'type': 'for_statement', 'children': ['126', '127', '128']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'confname'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'confnames'},{'id': '128', 'type': 'block', 'children': ['129', '133', '239', '283']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '132', 'type': 'None', 'children': []},{'id': '133', 'type': 'if_statement', 'children': ['134', '142']},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '136'], 'value': 'and'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'string', 'children': [], 'value': "'s3://'"},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'try_statement', 'children': ['144', '235']},{'id': '144', 'type': 'block', 'children': ['145', '148', '162']},{'id': '145', 'type': 'import_statement', 'children': ['146']},{'id': '146', 'type': 'dotted_name', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'boto'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '154']},{'id': '150', 'type': 'pattern_list', 'children': ['151', '152', '153']},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'bucket_name'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '154', 'type': 'subscript', 'children': ['155', '159']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '159', 'type': 'slice', 'children': ['160', '161']},{'id': '160', 'type': 'colon', 'children': []},{'id': '161', 'type': 'integer', 'children': [], 'value': '3'},{'id': '162', 'type': 'try_statement', 'children': ['163', '218']},{'id': '163', 'type': 'block', 'children': ['164', '172', '181', '189', '198', '206']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'boto'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'connect_s3'},{'id': '171', 'type': 'argument_list', 'children': []},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'get_bucket'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'bucket_name'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'key_name'},{'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '%'},{'id': '185', 'type': 'string', 'children': [], 'value': "'%s/%s'"},{'id': '186', 'type': 'tuple', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'confname'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'get_key'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'key_name'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'get_contents_as_string'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'if_statement', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'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': 'LOGGER'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216', '217']},{'id': '215', 'type': 'string', 'children': [], 'value': '"config loaded from \'s3://%s/%s\'"'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'bucket_name'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'key_name'},{'id': '218', 'type': 'except_clause', 'children': ['219', '233']},{'id': '219', 'type': 'as_pattern', 'children': ['220', '231']},{'id': '220', 'type': 'tuple', 'children': ['221', '226']},{'id': '221', 'type': 'attribute', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'boto'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'NoAuthHandlerFound'},{'id': '226', 'type': 'attribute', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'boto'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'S3ResponseError'},{'id': '231', 'type': 'as_pattern_target', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'pass_statement', 'children': []},{'id': '235', 'type': 'except_clause', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'pass_statement', 'children': []},{'id': '239', 'type': 'if_statement', 'children': ['240', '242']},{'id': '240', 'type': 'not_operator', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '242', 'type': 'block', 'children': ['243', '260']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'confpath'},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'locate_config'},{'id': '248', 'type': 'argument_list', 'children': ['249', '250', '251', '254', '257']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'confname'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '260', 'type': 'if_statement', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'confpath'},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'with_statement', 'children': ['264', '274']},{'id': '264', 'type': 'with_clause', 'children': ['265']},{'id': '265', 'type': 'with_item', 'children': ['266']},{'id': '266', 'type': 'as_pattern', 'children': ['267', '272']},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'confpath'},{'id': '271', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '272', 'type': 'as_pattern_target', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'conffile'},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'conffile'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '282', 'type': 'argument_list', 'children': []},{'id': '283', 'type': 'if_statement', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '285', 'type': 'block', 'children': ['286', '299', '315']},{'id': '286', 'type': 'if_statement', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'passphrase'},{'id': '288', 'type': 'block', 'children': ['289']},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'crypt'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'decrypt'},{'id': '296', 'type': 'argument_list', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'passphrase'},{'id': '299', 'type': 'if_statement', 'children': ['300', '305']},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '302', 'type': 'argument_list', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '304', 'type': 'string', 'children': [], 'value': "'decode'"},{'id': '305', 'type': 'block', 'children': ['306']},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '309', 'type': 'call', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '313', 'type': 'argument_list', 'children': ['314']},{'id': '314', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '315', 'type': 'for_statement', 'children': ['316', '317', '323']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '317', 'type': 'call', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '323', 'type': 'block', 'children': ['324']},{'id': '324', 'type': 'if_statement', 'children': ['325', '329', '347']},{'id': '325', 'type': 'not_operator', 'children': ['326']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '329', 'type': 'ERROR', 'children': ['330', '346']},{'id': '330', 'type': 'call', 'children': ['331', '332']},{'id': '331', 'type': 'string', 'children': [], 'value': "'\n look = re.match(r'"},{'id': '332', 'type': 'argument_list', 'children': ['333', '334']},{'id': '333', 'type': 'ERROR', 'children': [], 'value': '\\'},{'id': '334', 'type': 'binary_operator', 'children': ['335', '336', '337'], 'value': '+'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '336', 'type': 'ERROR', 'children': []},{'id': '337', 'type': 'binary_operator', 'children': ['338', '342', '345'], 'value': '*'},{'id': '338', 'type': 'binary_operator', 'children': ['339', '340', '341'], 'value': '*'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '340', 'type': 'ERROR', 'children': []},{'id': '341', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '342', 'type': 'ERROR', 'children': ['343']},{'id': '343', 'type': 'tuple', 'children': ['344']},{'id': '344', 'type': 'ERROR', 'children': []},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'look'},{'id': '347', 'type': 'block', 'children': ['348']},{'id': '348', 'type': 'try_statement', 'children': ['349', '379']},{'id': '349', 'type': 'block', 'children': ['350']},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'dictionary', 'children': ['357']},{'id': '357', 'type': 'pair', 'children': ['358', '368']},{'id': '358', 'type': 'call', 'children': ['359', '367']},{'id': '359', 'type': 'attribute', 'children': ['360', '366']},{'id': '360', 'type': 'call', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'look'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'integer', 'children': [], 'value': '1'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '367', 'type': 'argument_list', 'children': []},{'id': '368', 'type': 'call', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'eval'},{'id': '370', 'type': 'argument_list', 'children': ['371', '377', '378']},{'id': '371', 'type': 'call', 'children': ['372', '375']},{'id': '372', 'type': 'attribute', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'look'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '375', 'type': 'argument_list', 'children': ['376']},{'id': '376', 'type': 'integer', 'children': [], 'value': '2'},{'id': '377', 'type': 'dictionary', 'children': []},{'id': '378', 'type': 'dictionary', 'children': []},{'id': '379', 'type': 'except_clause', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '381', 'type': 'block', 'children': ['382']},{'id': '382', 'type': 'raise_statement', 'children': []},{'id': '383', 'type': 'return_statement', 'children': ['384']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'config'}
def load_config(app_name, *args, **kwargs): configure_logging() prefix = kwargs.get('prefix', 'etc') verbose = kwargs.get('verbose', False) location = kwargs.get('location', None) passphrase = kwargs.get('passphrase', os.getenv("%s_SETTINGS_CRYPT_KEY" % app_name.upper(), os.getenv("SETTINGS_CRYPT_KEY", None))) confnames = args if not location: location = os.getenv("%s_SETTINGS_LOCATION" % app_name.upper(), None) if not location: location = os.getenv("SETTINGS_LOCATION", None) if location: location = "%s/%s" % (location, app_name) config = {} for confname in confnames: content = None if location and location.startswith('s3://'): try: import boto _, bucket_name, prefix = urlparse(location)[:3] try: conn = boto.connect_s3() bucket = conn.get_bucket(bucket_name) key_name = '%s/%s' % (prefix, confname) key = bucket.get_key(key_name) content = key.get_contents_as_string() if verbose: LOGGER.info("config loaded from 's3://%s/%s'", bucket_name, key_name) except (boto.exception.NoAuthHandlerFound, boto.exception.S3ResponseError) as _: pass except ImportError: pass if not content: confpath = locate_config( confname, app_name, location=location, prefix=prefix, verbose=verbose) if confpath: with open(confpath, 'rb') as conffile: content = conffile.read() if content: if passphrase: content = crypt.decrypt(content, passphrase) if hasattr(content, 'decode'): content = content.decode('utf-8') for line in content.split('\n'): if not line.startswith(' look = re.match(r'(\w+)\s*=\s*(.*)', line) if look: try: config.update({look.group(1).upper(): eval(look.group(2), {}, {})}) except Exception: raise return config
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'predict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '8', 'type': 'list', 'children': [], 'value': '[]'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '17']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '16', 'type': 'integer', 'children': [], 'value': '1'},{'id': '17', 'type': 'while_statement', 'children': ['18', '19']},{'id': '18', 'type': 'integer', 'children': [], 'value': '1'},{'id': '19', 'type': 'block', 'children': ['20', '26', '213', '223', '267', '287', '294', '349', '397']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '26', 'type': 'if_statement', 'children': ['27', '34', '76']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '33'], 'value': '=='},{'id': '28', 'type': 'subscript', 'children': ['29', '32']},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'integer', 'children': [], 'value': '5'},{'id': '33', 'type': 'string', 'children': [], 'value': '"c"'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'if_statement', 'children': ['36', '49', '62']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '44'], 'value': '<='},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '39', 'type': 'subscript', 'children': ['40', '43']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'integer', 'children': [], 'value': '1'},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'integer', 'children': [], 'value': '2'},{'id': '49', 'type': 'block', 'children': ['50']},{'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': 'index'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '55', 'type': 'expression_list', 'children': ['56', '57']},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'subscript', 'children': ['58', '61']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'else_clause', 'children': ['63']},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '69']},{'id': '66', 'type': 'pattern_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '69', 'type': 'expression_list', 'children': ['70', '71']},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'subscript', 'children': ['72', '75']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'else_clause', 'children': ['77']},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'if_statement', 'children': ['79', '92', '105', '132']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '87'], 'value': 'in'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '82', 'type': 'subscript', 'children': ['83', '86']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '85', 'type': 'integer', 'children': [], 'value': '0'},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'subscript', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'integer', 'children': [], 'value': '2'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '98']},{'id': '95', 'type': 'pattern_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '98', 'type': 'expression_list', 'children': ['99', '100']},{'id': '99', 'type': 'integer', 'children': [], 'value': '0'},{'id': '100', 'type': 'subscript', 'children': ['101', '104']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '103', 'type': 'integer', 'children': [], 'value': '0'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'elif_clause', 'children': ['106', '119']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '114'], 'value': 'in'},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'subscript', 'children': ['115', '118']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'integer', 'children': [], 'value': '2'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '125']},{'id': '122', 'type': 'pattern_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '125', 'type': 'expression_list', 'children': ['126', '127']},{'id': '126', 'type': 'integer', 'children': [], 'value': '1'},{'id': '127', 'type': 'subscript', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'integer', 'children': [], 'value': '0'},{'id': '132', 'type': 'else_clause', 'children': ['133']},{'id': '133', 'type': 'block', 'children': ['134', '156']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '137', 'type': 'binary_operator', 'children': ['138', '148'], 'value': '+'},{'id': '138', 'type': 'binary_operator', 'children': ['139', '147'], 'value': '+'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'subscript', 'children': ['143', '146']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'string', 'children': [], 'value': '","'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'subscript', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '154', 'type': 'integer', 'children': [], 'value': '1'},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'index'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '161', 'type': 'expression_list', 'children': ['162', '163']},{'id': '162', 'type': 'integer', 'children': [], 'value': '0'},{'id': '163', 'type': 'list', 'children': ['164'], 'value': '[[0, 0, 0, {k: nodes[0][3].get(k, 0) + nodes[1][3].get(k, 0) for k in\n set(nodes[0][3]) | set(nodes[1][3])}]]'},{'id': '164', 'type': 'list', 'children': ['165', '166', '167', '168'], 'value': '[0, 0, 0, {k: nodes[0][3].get(k, 0) + nodes[1][3].get(k, 0) for k in\n set(nodes[0][3]) | set(nodes[1][3])}]'},{'id': '165', 'type': 'integer', 'children': [], 'value': '0'},{'id': '166', 'type': 'integer', 'children': [], 'value': '0'},{'id': '167', 'type': 'integer', 'children': [], 'value': '0'},{'id': '168', 'type': 'dictionary_comprehension', 'children': ['169', '194']},{'id': '169', 'type': 'pair', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '183'], 'value': '+'},{'id': '172', 'type': 'call', 'children': ['173', '180']},{'id': '173', 'type': 'attribute', 'children': ['174', '179']},{'id': '174', 'type': 'subscript', 'children': ['175', '178']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '177', 'type': 'integer', 'children': [], 'value': '0'},{'id': '178', 'type': 'integer', 'children': [], 'value': '3'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '182', 'type': 'integer', 'children': [], 'value': '0'},{'id': '183', 'type': 'call', 'children': ['184', '191']},{'id': '184', 'type': 'attribute', 'children': ['185', '190']},{'id': '185', 'type': 'subscript', 'children': ['186', '189']},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '188', 'type': 'integer', 'children': [], 'value': '1'},{'id': '189', 'type': 'integer', 'children': [], 'value': '3'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '193', 'type': 'integer', 'children': [], 'value': '0'},{'id': '194', 'type': 'for_in_clause', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '196', 'type': 'binary_operator', 'children': ['197', '205'], 'value': '|'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'subscript', 'children': ['201', '204']},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '203', 'type': 'integer', 'children': [], 'value': '0'},{'id': '204', 'type': 'integer', 'children': [], 'value': '3'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'subscript', 'children': ['209', '212']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '211', 'type': 'integer', 'children': [], 'value': '1'},{'id': '212', 'type': 'integer', 'children': [], 'value': '3'},{'id': '213', 'type': 'if_statement', 'children': ['214', '221']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'in'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '220', 'type': 'argument_list', 'children': []},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'continue_statement', 'children': []},{'id': '223', 'type': 'if_statement', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '225', 'type': 'block', 'children': ['226', '241']},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'suma'},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '240']},{'id': '233', 'type': 'attribute', 'children': ['234', '239']},{'id': '234', 'type': 'subscript', 'children': ['235', '238']},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '238', 'type': 'integer', 'children': [], 'value': '3'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'return_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'dictionary_comprehension', 'children': ['246', '254']},{'id': '246', 'type': 'pair', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '/'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'suma'},{'id': '254', 'type': 'for_in_clause', 'children': ['255', '258']},{'id': '255', 'type': 'pattern_list', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '258', 'type': 'call', 'children': ['259', '266']},{'id': '259', 'type': 'attribute', 'children': ['260', '265']},{'id': '260', 'type': 'subscript', 'children': ['261', '264']},{'id': '261', 'type': 'subscript', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '264', 'type': 'integer', 'children': [], 'value': '3'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '266', 'type': 'argument_list', 'children': []},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'prediction'},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '272', 'type': 'argument_list', 'children': ['273', '278']},{'id': '273', 'type': 'subscript', 'children': ['274', '277']},{'id': '274', 'type': 'subscript', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '277', 'type': 'integer', 'children': [], 'value': '3'},{'id': '278', 'type': 'keyword_argument', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '280', 'type': 'attribute', 'children': ['281', '286']},{'id': '281', 'type': 'subscript', 'children': ['282', '285']},{'id': '282', 'type': 'subscript', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '285', 'type': 'integer', 'children': [], 'value': '3'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '287', 'type': 'if_statement', 'children': ['288', '291']},{'id': '288', 'type': 'comparison_operator', 'children': ['289', '290'], 'value': '=='},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '290', 'type': 'list', 'children': [], 'value': '[]'},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'return_statement', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'prediction'},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '297', 'type': 'call', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '299', 'type': 'argument_list', 'children': ['300', '340', '346']},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '302', 'type': 'argument_list', 'children': ['303', '312']},{'id': '303', 'type': 'call', 'children': ['304', '311']},{'id': '304', 'type': 'attribute', 'children': ['305', '310']},{'id': '305', 'type': 'subscript', 'children': ['306', '309']},{'id': '306', 'type': 'subscript', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '309', 'type': 'integer', 'children': [], 'value': '3'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '311', 'type': 'argument_list', 'children': []},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'true_divide'},{'id': '316', 'type': 'argument_list', 'children': ['317', '326']},{'id': '317', 'type': 'call', 'children': ['318', '325']},{'id': '318', 'type': 'attribute', 'children': ['319', '324']},{'id': '319', 'type': 'subscript', 'children': ['320', '323']},{'id': '320', 'type': 'subscript', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '323', 'type': 'integer', 'children': [], 'value': '3'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '325', 'type': 'argument_list', 'children': []},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'call', 'children': ['332', '339']},{'id': '332', 'type': 'attribute', 'children': ['333', '338']},{'id': '333', 'type': 'subscript', 'children': ['334', '337']},{'id': '334', 'type': 'subscript', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '337', 'type': 'integer', 'children': [], 'value': '3'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '339', 'type': 'argument_list', 'children': []},{'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '342', 'type': 'call', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'integer', 'children': [], 'value': '1'},{'id': '346', 'type': 'keyword_argument', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '348', 'type': 'True', 'children': []},{'id': '349', 'type': 'if_statement', 'children': ['350', '353', '376']},{'id': '350', 'type': 'comparison_operator', 'children': ['351', '352'], 'value': '=='},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'prediction'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '353', 'type': 'block', 'children': ['354']},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'assignment', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'margin'},{'id': '357', 'type': 'conditional_expression', 'children': ['358', '369', '375'], 'value': 'if'},{'id': '358', 'type': 'binary_operator', 'children': ['359', '364'], 'value': '-'},{'id': '359', 'type': 'subscript', 'children': ['360', '363']},{'id': '360', 'type': 'subscript', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '362', 'type': 'integer', 'children': [], 'value': '0'},{'id': '363', 'type': 'integer', 'children': [], 'value': '1'},{'id': '364', 'type': 'subscript', 'children': ['365', '368']},{'id': '365', 'type': 'subscript', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '367', 'type': 'integer', 'children': [], 'value': '1'},{'id': '368', 'type': 'integer', 'children': [], 'value': '1'},{'id': '369', 'type': 'comparison_operator', 'children': ['370', '374'], 'value': '>'},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '372', 'type': 'argument_list', 'children': ['373']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '374', 'type': 'integer', 'children': [], 'value': '1'},{'id': '375', 'type': 'integer', 'children': [], 'value': '1'},{'id': '376', 'type': 'else_clause', 'children': ['377']},{'id': '377', 'type': 'block', 'children': ['378']},{'id': '378', 'type': 'expression_statement', 'children': ['379']},{'id': '379', 'type': 'assignment', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'margin'},{'id': '381', 'type': 'binary_operator', 'children': ['382', '392'], 'value': '-'},{'id': '382', 'type': 'call', 'children': ['383', '389']},{'id': '383', 'type': 'attribute', 'children': ['384', '388']},{'id': '384', 'type': 'call', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '386', 'type': 'argument_list', 'children': ['387']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '389', 'type': 'argument_list', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '391', 'type': 'integer', 'children': [], 'value': '0'},{'id': '392', 'type': 'subscript', 'children': ['393', '396']},{'id': '393', 'type': 'subscript', 'children': ['394', '395']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'probs'},{'id': '395', 'type': 'integer', 'children': [], 'value': '0'},{'id': '396', 'type': 'integer', 'children': [], 'value': '1'},{'id': '397', 'type': 'return_statement', 'children': ['398']},{'id': '398', 'type': 'expression_list', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'margin'}
def predict(tree, x, y=[], dist=False): node_id = 1 while 1: nodes = tree[node_id] if nodes[0][5] == "c": if x[nodes[0][1]] <= nodes[0][2]: index, node_id = 0, nodes[0][0] else: index, node_id = 1, nodes[1][0] else: if x[nodes[0][1]] in nodes[0][2]: index, node_id = 0, nodes[0][0] elif x[nodes[1][1]] in nodes[1][2]: index, node_id = 1, nodes[1][0] else: node_id = str(nodes[0][0]) + "," + str(nodes[1][0]) index, nodes = 0, [[0, 0, 0, {k: nodes[0][3].get(k, 0) + nodes[1][3].get(k, 0) for k in set(nodes[0][3]) | set(nodes[1][3])}]] if node_id in tree.keys(): continue if dist: suma = sum(nodes[index][3].values()) return Counter({k: v / float(suma) for k, v in nodes[index][3].iteritems()}) prediction = max(nodes[index][3], key=nodes[index][3].get) if y == []: return prediction probs = sorted( zip(nodes[index][3].keys(), np.true_divide(nodes[index][3].values(), np.sum(nodes[index][3].values()))), key=itemgetter(1), reverse=True) if prediction == y: margin = probs[0][1] - probs[1][1] if len(probs) > 1 else 1 else: margin = dict(probs).get(y, 0) - probs[0][1] return node_id, margin
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pay_with_account_credit_cards'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'invoice_id'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'generic_type', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '8', 'type': 'type_parameter', 'children': ['9']},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'Transaction'},{'id': '11', 'type': 'block', 'children': ['12', '22']},{'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': 'logger'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': "'invoice-payment-started'"},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'invoice_id'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'invoice_id'},{'id': '22', 'type': 'with_statement', 'children': ['23', '30']},{'id': '23', 'type': 'with_clause', 'children': ['24']},{'id': '24', 'type': 'with_item', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'atomic'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'block', 'children': ['31', '48', '66', '78', '91', '104', '110', '122', '146', '155', '289']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '34', 'type': 'call', 'children': ['35', '44']},{'id': '35', 'type': 'attribute', 'children': ['36', '43']},{'id': '36', 'type': 'call', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'Invoice'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'select_for_update'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'invoice_id'},{'id': '48', 'type': 'if_statement', 'children': ['49', '53']},{'id': '49', 'type': 'not_operator', 'children': ['50']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'in_payable_state'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'raise_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'PreconditionError'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'Cannot pay invoice with status {}.'"},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'due'},{'id': '69', 'type': 'call', 'children': ['70', '77']},{'id': '70', 'type': 'attribute', 'children': ['71', '76']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'due'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'monies'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'if_statement', 'children': ['79', '85']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '84'], 'value': '=='},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'due'},{'id': '84', 'type': 'integer', 'children': [], 'value': '0'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'raise_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'PreconditionError'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'string', 'children': [], 'value': "'Cannot pay empty invoice.'"},{'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': 'due'},{'id': '97', 'type': 'integer', 'children': [], 'value': '1'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'raise_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'PreconditionError'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'string', 'children': [], 'value': "'Cannot pay invoice with more than one currency.'"},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'amount'},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'due'},{'id': '109', 'type': 'integer', 'children': [], 'value': '0'},{'id': '110', 'type': 'if_statement', 'children': ['111', '116']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': '<='},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'amount'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'amount'},{'id': '115', 'type': 'integer', 'children': [], 'value': '0'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'raise_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'PreconditionError'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'string', 'children': [], 'value': "'Cannot pay invoice with non-positive amount.'"},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'valid_credit_cards'},{'id': '125', 'type': 'call', 'children': ['126', '144']},{'id': '126', 'type': 'attribute', 'children': ['127', '143']},{'id': '127', 'type': 'call', 'children': ['128', '137']},{'id': '128', 'type': 'attribute', 'children': ['129', '136']},{'id': '129', 'type': 'call', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'CreditCard'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'valid'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'account'},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'account'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '146', 'type': 'if_statement', 'children': ['147', '149']},{'id': '147', 'type': 'not_operator', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'valid_credit_cards'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'raise_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'PreconditionError'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'string', 'children': [], 'value': "'No valid credit card on account.'"},{'id': '155', 'type': 'for_statement', 'children': ['156', '157', '158']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'credit_card'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'valid_credit_cards'},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'try_statement', 'children': ['160', '267']},{'id': '160', 'type': 'block', 'children': ['161', '185', '222']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '166']},{'id': '163', 'type': 'pattern_list', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'payment_psp_object'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'psp'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'charge_credit_card'},{'id': '170', 'type': 'argument_list', 'children': ['171', '176', '179']},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'credit_card_psp_object'},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'credit_card'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'psp_object'},{'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'amount'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'amount'},{'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'client_ref'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'invoice_id'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'payment'},{'id': '188', 'type': 'call', 'children': ['189', '194']},{'id': '189', 'type': 'attribute', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'Transaction'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'create'},{'id': '194', 'type': 'argument_list', 'children': ['195', '200', '203', '206', '209', '214', '219']},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'account'},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'account'},{'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'amount'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'amount'},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'payment_method'},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'credit_card'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'credit_card_number'},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'credit_card'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'psp_object'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'payment_psp_object'},{'id': '222', 'type': 'if_statement', 'children': ['223', '224', '252']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '224', 'type': 'block', 'children': ['225', '231', '237', '250']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'pay'},{'id': '230', 'type': 'argument_list', 'children': []},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '236', 'type': 'argument_list', 'children': []},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '242', 'type': 'argument_list', 'children': ['243', '244', '247']},{'id': '243', 'type': 'string', 'children': [], 'value': "'invoice-payment-success'"},{'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'invoice_id'},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'payment'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'payment'},{'id': '250', 'type': 'return_statement', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'payment'},{'id': '252', 'type': 'else_clause', 'children': ['253']},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '259', 'type': 'argument_list', 'children': ['260', '261', '264']},{'id': '260', 'type': 'string', 'children': [], 'value': "'invoice-payment-failure'"},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'invoice'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'invoice_id'},{'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'payment'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'payment'},{'id': '267', 'type': 'except_clause', 'children': ['268', '272']},{'id': '268', 'type': 'as_pattern', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '270', 'type': 'as_pattern_target', 'children': ['271']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '272', 'type': 'block', 'children': ['273']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '278', 'type': 'argument_list', 'children': ['279', '280', '283', '286']},{'id': '279', 'type': 'string', 'children': [], 'value': "'invoice-payment-error'"},{'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'invoice_id'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'invoice_id'},{'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'credit_card'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'credit_card'},{'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '289', 'type': 'return_statement', 'children': ['290']},{'id': '290', 'type': 'None', 'children': []}
def pay_with_account_credit_cards(invoice_id) -> Optional[Transaction]: logger.debug('invoice-payment-started', invoice_id=invoice_id) with transaction.atomic(): invoice = Invoice.objects.select_for_update().get(pk=invoice_id) if not invoice.in_payable_state: raise PreconditionError('Cannot pay invoice with status {}.'.format(invoice.status)) due = invoice.due().monies() if len(due) == 0: raise PreconditionError('Cannot pay empty invoice.') if len(due) > 1: raise PreconditionError('Cannot pay invoice with more than one currency.') amount = due[0] if amount.amount <= 0: raise PreconditionError('Cannot pay invoice with non-positive amount.') valid_credit_cards = CreditCard.objects.valid().filter(account=invoice.account).order_by('status') if not valid_credit_cards: raise PreconditionError('No valid credit card on account.') for credit_card in valid_credit_cards: try: success, payment_psp_object = psp.charge_credit_card( credit_card_psp_object=credit_card.psp_object, amount=amount, client_ref=str(invoice_id)) payment = Transaction.objects.create( account=invoice.account, invoice=invoice, amount=amount, success=success, payment_method=credit_card.type, credit_card_number=credit_card.number, psp_object=payment_psp_object) if success: invoice.pay() invoice.save() logger.info('invoice-payment-success', invoice=invoice_id, payment=payment) return payment else: logger.info('invoice-payment-failure', invoice=invoice_id, payment=payment) except Exception as e: logger.error('invoice-payment-error', invoice_id=invoice_id, credit_card=credit_card, exc_info=e) return None