sequence
stringlengths
1.19k
35k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteReplaceAppletInLayout'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '11', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'newApplet'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'tuple', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'QtmacsApplet'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '11', 'type': 'typed_default_parameter', 'children': ['12', '13', '17']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'oldApplet'}, {'id': '13', 'type': 'type', 'children': ['14']}; {'id': '14', 'type': 'tuple', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'QtmacsApplet'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'typed_default_parameter', 'children': ['19', '20', '22']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'windowObj'}; {'id': '20', 'type': 'type', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'QtmacsWindow'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'block', 'children': ['24', '46', '68', '103', '124', '143', '165', '171', '185', '197', '228', '237', '245', '253', '260']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '30', '40']}, {'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': 'oldApplet'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'oldAppObj'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'qteGetAppletHandle'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'oldApplet'}; {'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': 'oldAppObj'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'oldApplet'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '52', '62']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'newApplet'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'newAppObj'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'qteGetAppletHandle'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'newApplet'}; {'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', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'newAppObj'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'newApplet'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '72']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'windowObj'}, {'id': '71', 'type': 'None', 'children': []}; {'id': '72', 'type': 'block', 'children': ['73', '81']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'windowObj'}; {'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': 'qteActiveWindow'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'if_statement', 'children': ['82', '85']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'windowObj'}; {'id': '84', 'type': 'None', 'children': []}, {'id': '85', 'type': 'block', 'children': ['86', '90', '102']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'Cannot determine the currently active window.'"}; {'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': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'stack_info'}, {'id': '101', 'type': 'True', 'children': []}; {'id': '102', 'type': 'return_statement', 'children': []}, {'id': '103', 'type': 'if_statement', 'children': ['104', '113']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '112'], 'value': '=='}, {'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': 'windowObj'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'qteAppletSplitter'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '111', 'type': 'argument_list', 'children': []}; {'id': '112', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '113', 'type': 'block', 'children': ['114', '123']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '121']}; {'id': '116', 'type': 'attribute', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'windowObj'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'qteAppletSplitter'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'qteAddWidget'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'newAppObj'}, {'id': '123', 'type': 'return_statement', 'children': []}; {'id': '124', 'type': 'if_statement', 'children': ['125', '128']}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'oldAppObj'}, {'id': '127', 'type': 'None', 'children': []}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'oldAppObj'}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'qteNextApplet'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '140']}, {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'numSkip'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'windowObj'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'windowObj'}, {'id': '143', 'type': 'if_statement', 'children': ['144', '147']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'is'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'oldAppObj'}; {'id': '146', 'type': 'None', 'children': []}, {'id': '147', 'type': 'block', 'children': ['148', '152', '164']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '151', 'type': 'string', 'children': [], 'value': "'Applet to replace does not exist.'"}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '159']}; {'id': '154', 'type': 'attribute', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'stack_info'}, {'id': '163', 'type': 'True', 'children': []}; {'id': '164', 'type': 'return_statement', 'children': []}, {'id': '165', 'type': 'if_statement', 'children': ['166', '169']}; {'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': 'is'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'newAppObj'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'oldAppObj'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'return_statement', 'children': []}, {'id': '171', 'type': 'if_statement', 'children': ['172', '183']}; {'id': '172', 'type': 'boolean_operator', 'children': ['173', '178'], 'value': 'and'}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'oldAppObj'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'qteIsVisible'}, {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'newAppObj'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'qteIsVisible'}; {'id': '182', 'type': 'argument_list', 'children': []}, {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'return_statement', 'children': []}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': '_qteFindAppletInSplitter'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'oldAppObj'}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'windowObj'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'qteAppletSplitter'}, {'id': '197', 'type': 'if_statement', 'children': ['198', '201']}; {'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': 'is'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '200', 'type': 'None', 'children': []}, {'id': '201', 'type': 'block', 'children': ['202', '218', '227']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '205', 'type': 'parenthesized_expression', 'children': ['206'], 'value': '()'}; {'id': '206', 'type': 'call', 'children': ['207', '212']}, {'id': '207', 'type': 'attribute', 'children': ['208', '211']}; {'id': '208', 'type': 'concatenated_string', 'children': ['209', '210']}, {'id': '209', 'type': 'string', 'children': [], 'value': "'Applet <b>{}</b> not replaced because it is not'"}; {'id': '210', 'type': 'string', 'children': [], 'value': "'in the layout.'"}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'oldAppObj'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'qteAppletID'}, {'id': '217', 'type': 'argument_list', 'children': []}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '225']}; {'id': '220', 'type': 'attribute', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '227', 'type': 'return_statement', 'children': []}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'oldAppIdx'}, {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'indexOf'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'oldAppObj'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'sizes'}; {'id': '240', 'type': 'call', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'sizes'}; {'id': '244', 'type': 'argument_list', 'children': []}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'qteInsertWidget'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'oldAppIdx'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'newAppObj'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '258']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'oldAppObj'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'hide'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'True', 'children': []}; {'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': 'split'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'setSizes'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}
def qteReplaceAppletInLayout(self, newApplet: (QtmacsApplet, str), oldApplet: (QtmacsApplet, str)=None, windowObj: QtmacsWindow=None): if isinstance(oldApplet, str): oldAppObj = self.qteGetAppletHandle(oldApplet) else: oldAppObj = oldApplet if isinstance(newApplet, str): newAppObj = self.qteGetAppletHandle(newApplet) else: newAppObj = newApplet if windowObj is None: windowObj = self.qteActiveWindow() if windowObj is None: msg = 'Cannot determine the currently active window.' self.qteLogger.warning(msg, stack_info=True) return if windowObj.qteAppletSplitter.count() == 0: windowObj.qteAppletSplitter.qteAddWidget(newAppObj) return if oldAppObj is None: oldAppObj = self.qteNextApplet(numSkip=0, windowObj=windowObj) if oldAppObj is None: msg = 'Applet to replace does not exist.' self.qteLogger.error(msg, stack_info=True) return if newAppObj is oldAppObj: return if oldAppObj.qteIsVisible() and newAppObj.qteIsVisible(): return split = self._qteFindAppletInSplitter( oldAppObj, windowObj.qteAppletSplitter) if split is None: msg = ('Applet <b>{}</b> not replaced because it is not' 'in the layout.'.format(oldAppObj.qteAppletID())) self.qteLogger.warning(msg) return oldAppIdx = split.indexOf(oldAppObj) sizes = split.sizes() split.qteInsertWidget(oldAppIdx, newAppObj) oldAppObj.hide(True) split.setSizes(sizes)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteRemoveAppletFromLayout'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'applet'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'tuple', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'QtmacsApplet'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '11', 'type': 'block', 'children': ['12', '34', '58', '64', '137', '146', '153', '187', '196']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '18', '28']}, {'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': 'applet'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'appletObj'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'qteGetAppletHandle'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'applet'}; {'id': '28', 'type': 'else_clause', 'children': ['29']}, {'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': 'appletObj'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'applet'}; {'id': '34', 'type': 'for_statement', 'children': ['35', '36', '39']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_qteWindowList'}, {'id': '39', 'type': 'block', 'children': ['40', '52']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_qteFindAppletInSplitter'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'appletObj'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'window'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'qteAppletSplitter'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'break_statement', 'children': []}; {'id': '58', 'type': 'if_statement', 'children': ['59', '62']}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'is'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'return_statement', 'children': []}; {'id': '64', 'type': 'if_statement', 'children': ['65', '80']}, {'id': '65', 'type': 'boolean_operator', 'children': ['66', '72'], 'value': 'and'}; {'id': '66', 'type': 'parenthesized_expression', 'children': ['67'], 'value': '()'}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'window'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'qteAppletSplitter'}; {'id': '72', 'type': 'parenthesized_expression', 'children': ['73'], 'value': '()'}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '79'], 'value': '=='}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '78', 'type': 'argument_list', 'children': []}, {'id': '79', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '80', 'type': 'block', 'children': ['81', '93', '104', '129', '136']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '91']}, {'id': '83', 'type': 'attribute', 'children': ['84', '90']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'widget'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'hide'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'True', 'children': []}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'nextApp'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'qteNextApplet'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'windowObj'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '104', 'type': 'if_statement', 'children': ['105', '108']}, {'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'is'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'nextApp'}, {'id': '107', 'type': 'None', 'children': []}; {'id': '108', 'type': 'block', 'children': ['109', '123']}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'nextApp'}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'qteNextApplet'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '120']}, {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'skipInvisible'}, {'id': '119', 'type': 'False', 'children': []}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'skipVisible'}; {'id': '122', 'type': 'True', 'children': []}, {'id': '123', 'type': 'if_statement', 'children': ['124', '127']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'is'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'nextApp'}; {'id': '126', 'type': 'None', 'children': []}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'return_statement', 'children': []}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'qteAddWidget'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'nextApp'}; {'id': '136', 'type': 'return_statement', 'children': []}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'appletIdx'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'indexOf'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'appletObj'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'appletObj'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'hide'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'True', 'children': []}, {'id': '153', 'type': 'if_statement', 'children': ['154', '161']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '160'], 'value': '!='}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '161', 'type': 'block', 'children': ['162', '178']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '165', 'type': 'parenthesized_expression', 'children': ['166'], 'value': '()'}; {'id': '166', 'type': 'call', 'children': ['167', '172']}, {'id': '167', 'type': 'attribute', 'children': ['168', '171']}; {'id': '168', 'type': 'concatenated_string', 'children': ['169', '170']}, {'id': '169', 'type': 'string', 'children': [], 'value': "'Splitter has <b>{}</b> elements left instead of'"}; {'id': '170', 'type': 'string', 'children': [], 'value': "' exactly one.'"}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '185']}; {'id': '180', 'type': 'attribute', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'otherWidget'}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'widget'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '196', 'type': 'if_statement', 'children': ['197', '204', '262']}, {'id': '197', 'type': 'comparison_operator', 'children': ['198', '203'], 'value': '=='}; {'id': '198', 'type': 'attribute', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'otherWidget'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'widgetSignature'}, {'id': '203', 'type': 'string', 'children': [], 'value': "'__QtmacsLayoutSplitter__'"}; {'id': '204', 'type': 'block', 'children': ['205', '249', '256']}, {'id': '205', 'type': 'for_statement', 'children': ['206', '207', '215']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'ii'}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'otherWidget'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '214', 'type': 'argument_list', 'children': []}, {'id': '215', 'type': 'block', 'children': ['216', '225']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'otherWidget'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'widget'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '225', 'type': 'if_statement', 'children': ['226', '229', '237']}; {'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': '=='}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'appletIdx'}; {'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': 'split'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'qteAddWidget'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '237', 'type': 'else_clause', 'children': ['238']}; {'id': '238', 'type': 'block', 'children': ['239']}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'qteInsertWidget'}; {'id': '244', 'type': 'argument_list', 'children': ['245', '248']}, {'id': '245', 'type': 'binary_operator', 'children': ['246', '247'], 'value': '+'}; {'id': '246', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'ii'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'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': 'otherWidget'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'setParent'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'None', 'children': []}; {'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': 'otherWidget'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'close'}, {'id': '261', 'type': 'argument_list', 'children': []}; {'id': '262', 'type': 'else_clause', 'children': ['263']}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'if_statement', 'children': ['265', '270']}, {'id': '265', 'type': 'comparison_operator', 'children': ['266', '267'], 'value': 'is'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'window'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'qteAppletSplitter'}; {'id': '270', 'type': 'block', 'children': ['271', '282', '289']}, {'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': 'otherWidget'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'qteReparent'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '281', 'type': 'argument_list', 'children': []}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'call', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'setParent'}, {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'None', 'children': []}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'call', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'close'}
def qteRemoveAppletFromLayout(self, applet: (QtmacsApplet, str)): if isinstance(applet, str): appletObj = self.qteGetAppletHandle(applet) else: appletObj = applet for window in self._qteWindowList: split = self._qteFindAppletInSplitter( appletObj, window.qteAppletSplitter) if split is not None: break if split is None: return if (split is window.qteAppletSplitter) and (split.count() == 1): split.widget(0).hide(True) nextApp = self.qteNextApplet(windowObj=window) if nextApp is None: nextApp = self.qteNextApplet(skipInvisible=False, skipVisible=True) if nextApp is None: return split.qteAddWidget(nextApp) return appletIdx = split.indexOf(appletObj) appletObj.hide(True) if split.count() != 1: msg = ('Splitter has <b>{}</b> elements left instead of' ' exactly one.'.format(split.count())) self.qteLogger.warning(msg) otherWidget = split.widget(0) if otherWidget._qteAdmin.widgetSignature == '__QtmacsLayoutSplitter__': for ii in range(otherWidget.count()): obj = otherWidget.widget(0) if appletIdx == 0: split.qteAddWidget(obj) else: split.qteInsertWidget(1 + ii, obj) otherWidget.setParent(None) otherWidget.close() else: if split is not window.qteAppletSplitter: otherWidget.qteReparent(split.parent()) split.setParent(None) split.close()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteKillApplet'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'appletID'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '9', 'type': 'block', 'children': ['10', '24', '49', '64', '70', '78', '96', '122', '135', '149', '158', '164']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ID_list'}, {'id': '13', 'type': 'list_comprehension', 'children': ['14', '19']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'qteAppletID'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28', '30']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'not'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'appletID'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ID_list'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': []}; {'id': '30', 'type': 'else_clause', 'children': ['31']}, {'id': '31', 'type': 'block', 'children': ['32', '41']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ID_list'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'appletID'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'appObj'}; {'id': '44', 'type': 'subscript', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '56']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'qteIsMiniApplet'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'appObj'}; {'id': '56', 'type': 'block', 'children': ['57', '63']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'qteKillMiniApplet'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'return_statement', 'children': []}; {'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': 'appObj'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'qteToBeKilled'}, {'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': 'window'}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'appObj'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'qteParentWindow'}, {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'newApplet'}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'qteNextApplet'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '90', '93']}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'numSkip'}; {'id': '88', 'type': 'unary_operator', 'children': ['89'], 'value': '-'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'skipInvisible'}; {'id': '92', 'type': 'False', 'children': []}, {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'skipVisible'}, {'id': '95', 'type': 'True', 'children': []}; {'id': '96', 'type': 'if_statement', 'children': ['97', '106', '111']}, {'id': '97', 'type': 'boolean_operator', 'children': ['98', '102'], 'value': 'or'}; {'id': '98', 'type': 'parenthesized_expression', 'children': ['99'], 'value': '()'}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'newApplet'}, {'id': '101', 'type': 'None', 'children': []}; {'id': '102', 'type': 'parenthesized_expression', 'children': ['103'], 'value': '()'}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'newApplet'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'appObj'}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'newApplet'}; {'id': '110', 'type': 'None', 'children': []}, {'id': '111', 'type': 'else_clause', 'children': ['112']}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'qteReplaceAppletInLayout'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120', '121']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'newApplet'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'appObj'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '128']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '127'], 'value': 'is'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': '_qteActiveApplet'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'appObj'}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': '_qteActiveApplet'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'newApplet'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '142']}, {'id': '137', 'type': 'attribute', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'string', 'children': [], 'value': "'Kill applet: <b>{}</b>'"}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'appletID'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '156']}, {'id': '151', 'type': 'attribute', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'appObj'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'appObj'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'close'}, {'id': '163', 'type': 'argument_list', 'children': []}; {'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': 'sip'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'delete'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}
def qteKillApplet(self, appletID: str): ID_list = [_.qteAppletID() for _ in self._qteAppletList] if appletID not in ID_list: return else: idx = ID_list.index(appletID) appObj = self._qteAppletList[idx] if self.qteIsMiniApplet(appObj): self.qteKillMiniApplet() return appObj.qteToBeKilled() window = appObj.qteParentWindow() newApplet = self.qteNextApplet(numSkip=-1, skipInvisible=False, skipVisible=True) if (newApplet is None) or (newApplet is appObj): newApplet = None else: self.qteReplaceAppletInLayout(newApplet, appObj, window) if self._qteActiveApplet is appObj: self._qteActiveApplet = newApplet self.qteLogger.debug('Kill applet: <b>{}</b>'.format(appletID)) self._qteAppletList.remove(appObj) appObj.close() sip.delete(appObj)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteRunHook'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'hookName'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'msgObj'}, {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'QtmacsMessage'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '21', '27', '38', '45']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'reg'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_qteRegistryHooks'}, {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'not'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'hookName'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'reg'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'return_statement', 'children': []}, {'id': '27', 'type': 'if_statement', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'msgObj'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'msgObj'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'QtmacsMessage'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'msgObj'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'setHookName'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'hookName'}, {'id': '45', 'type': 'for_statement', 'children': ['46', '47', '50']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'fun'}, {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'reg'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'hookName'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'try_statement', 'children': ['52', '58']}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'fun'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'msgObj'}; {'id': '58', 'type': 'except_clause', 'children': ['59', '63']}, {'id': '59', 'type': 'as_pattern', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '61', 'type': 'as_pattern_target', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '63', 'type': 'block', 'children': ['64', '83', '87', '103']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'string', 'children': [], 'value': "'<b>{}</b>-hook function <b>{}</b>'"}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'hookName'}, {'id': '73', 'type': 'subscript', 'children': ['74', '78']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'fun'}; {'id': '78', 'type': 'slice', 'children': ['79', '80', '81']}, {'id': '79', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '80', 'type': 'colon', 'children': []}, {'id': '81', 'type': 'unary_operator', 'children': ['82'], 'value': '-'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'augmented_assignment', 'children': ['85', '86'], 'value': '+='}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '86', 'type': 'string', 'children': [], 'value': '" did not execute properly."'}, {'id': '87', 'type': 'if_statement', 'children': ['88', '93']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'QtmacsArgumentError'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'augmented_assignment', 'children': ['96', '97'], 'value': '+='}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '+'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'<br/>'"}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '110']}, {'id': '105', 'type': 'attribute', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112', '115']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'exc_info'}; {'id': '114', 'type': 'True', 'children': []}, {'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'stack_info'}, {'id': '117', 'type': 'True', 'children': []}
def qteRunHook(self, hookName: str, msgObj: QtmacsMessage=None): reg = self._qteRegistryHooks if hookName not in reg: return if msgObj is None: msgObj = QtmacsMessage() msgObj.setHookName(hookName) for fun in reg[hookName]: try: fun(msgObj) except Exception as err: msg = '<b>{}</b>-hook function <b>{}</b>'.format( hookName, str(fun)[1:-1]) msg += " did not execute properly." if isinstance(err, QtmacsArgumentError): msg += '<br/>' + str(err) self.qteLogger.exception(msg, exc_info=True, stack_info=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteMacroNameMangling'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'macroCls'}; {'id': '6', 'type': 'block', 'children': ['7', '20', '35']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16', '17']}, {'id': '15', 'type': 'string', 'children': [], 'value': 'r"([A-Z])"'}; {'id': '16', 'type': 'string', 'children': [], 'value': "r'-\\1'"}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'macroCls'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '26']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': '=='}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '32', 'type': 'slice', 'children': ['33', '34']}, {'id': '33', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '34', 'type': 'colon', 'children': []}, {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'macroName'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'lower'}
def qteMacroNameMangling(self, macroCls): macroName = re.sub(r"([A-Z])", r'-\1', macroCls.__name__) if macroName[0] == '-': macroName = macroName[1:] return macroName.lower()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteRegisterMacro'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'macroCls'}; {'id': '6', 'type': 'typed_default_parameter', 'children': ['7', '8', '10']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'replaceMacro'}; {'id': '8', 'type': 'type', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'typed_default_parameter', 'children': ['12', '13', '15']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'macroName'}, {'id': '13', 'type': 'type', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '46', '86', '119', '125', '160', '195', '199', '328']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '24']}; {'id': '18', 'type': 'not_operator', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'issubclass'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'macroCls'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'QtmacsMacro'}; {'id': '24', 'type': 'block', 'children': ['25', '40']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '28', 'type': 'tuple', 'children': ['29', '30', '31']}, {'id': '29', 'type': 'string', 'children': [], 'value': "'macroCls'"}; {'id': '30', 'type': 'string', 'children': [], 'value': "'class QtmacsMacro'"}, {'id': '31', 'type': 'subscript', 'children': ['32', '39']}; {'id': '32', 'type': 'subscript', 'children': ['33', '38']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '40', 'type': 'raise_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'QtmacsArgumentError'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'list_splat', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '46', 'type': 'try_statement', 'children': ['47', '54']}, {'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': 'macroObj'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'macroCls'}, {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'except_clause', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '56', 'type': 'block', 'children': ['57', '61', '72', '84']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'The macro <b>{}</b> has a faulty constructor.'"}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'macroCls'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '79']}; {'id': '74', 'type': 'attribute', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'stack_info'}, {'id': '83', 'type': 'True', 'children': []}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'None', 'children': []}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'macroName'}, {'id': '89', 'type': 'None', 'children': []}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'if_statement', 'children': ['92', '99', '109']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '98'], 'value': 'is'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'macroObj'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'qteMacroName'}, {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'None', 'children': []}, {'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': 'macroName'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'qteMacroNameMangling'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'macroCls'}, {'id': '109', 'type': 'else_clause', 'children': ['110']}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'macroObj'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'qteMacroName'}; {'id': '118', 'type': 'argument_list', 'children': []}, {'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': 'macroObj'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': '_qteMacroName'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'macroName'}, {'id': '125', 'type': 'if_statement', 'children': ['126', '136']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '135'], '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': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'macroObj'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'qteAppletSignature'}; {'id': '134', 'type': 'argument_list', 'children': []}, {'id': '135', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '136', 'type': 'block', 'children': ['137', '146', '158']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'string', 'children': [], 'value': "'Macro <b>{}</b> has no applet signatures.'"}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '153']}; {'id': '148', 'type': 'attribute', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '153', 'type': 'argument_list', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'stack_info'}, {'id': '157', 'type': 'True', 'children': []}; {'id': '158', 'type': 'return_statement', 'children': ['159']}, {'id': '159', 'type': 'None', 'children': []}; {'id': '160', 'type': 'if_statement', 'children': ['161', '171']}, {'id': '161', 'type': 'comparison_operator', 'children': ['162', '170'], 'value': '=='}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'macroObj'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'qteWidgetSignature'}, {'id': '169', 'type': 'argument_list', 'children': []}; {'id': '170', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '171', 'type': 'block', 'children': ['172', '181', '193']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'string', 'children': [], 'value': "'Macro <b>{}</b> has no widget signatures.'"}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'macroName'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '188']}, {'id': '183', 'type': 'attribute', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '188', 'type': 'argument_list', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'stack_info'}; {'id': '192', 'type': 'True', 'children': []}, {'id': '193', 'type': 'return_statement', 'children': ['194']}; {'id': '194', 'type': 'None', 'children': []}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'anyRegistered'}; {'id': '198', 'type': 'False', 'children': []}, {'id': '199', 'type': 'for_statement', 'children': ['200', '201', '206']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'app_sig'}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'macroObj'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'qteAppletSignature'}, {'id': '205', 'type': 'argument_list', 'children': []}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'for_statement', 'children': ['208', '209', '214']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'wid_sig'}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'macroObj'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'qteWidgetSignature'}, {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'block', 'children': ['215', '222', '297', '305', '315', '324']}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'macroNameInternal'}; {'id': '218', 'type': 'tuple', 'children': ['219', '220', '221']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'app_sig'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'wid_sig'}; {'id': '222', 'type': 'if_statement', 'children': ['223', '228']}, {'id': '223', 'type': 'comparison_operator', 'children': ['224', '225'], 'value': 'in'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'macroNameInternal'}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': '_qteRegistryMacros'}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'if_statement', 'children': ['230', '231', '272']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'replaceMacro'}, {'id': '231', 'type': 'block', 'children': ['232', '243', '247', '257', '266']}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '235', 'type': 'call', 'children': ['236', '241']}; {'id': '236', 'type': 'attribute', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': '_qteRegistryMacros'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'macroNameInternal'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '246', 'type': 'string', 'children': [], 'value': "'Replacing existing macro <b>{}</b> with new {}.'"}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '250', 'type': 'call', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '254', 'type': 'argument_list', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'macroNameInternal'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'macroObj'}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'call', 'children': ['259', '264']}, {'id': '259', 'type': 'attribute', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'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': 'tmp'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'deleteLater'}, {'id': '271', 'type': 'argument_list', 'children': []}; {'id': '272', 'type': 'else_clause', 'children': ['273']}, {'id': '273', 'type': 'block', 'children': ['274', '278', '287', '296']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'assignment', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '277', 'type': 'string', 'children': [], 'value': "'Macro <b>{}</b> already exists (not replaced).'"}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}, {'id': '279', 'type': 'assignment', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'macroNameInternal'}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '294']}, {'id': '289', 'type': 'attribute', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '296', 'type': 'continue_statement', 'children': []}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '304']}, {'id': '299', 'type': 'subscript', 'children': ['300', '303']}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': '_qteRegistryMacros'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'macroNameInternal'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'macroObj'}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '308', 'type': 'parenthesized_expression', 'children': ['309'], 'value': '()'}, {'id': '309', 'type': 'call', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'string', 'children': [], 'value': "'Macro <b>{}</b> successfully registered.'"}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '313', 'type': 'argument_list', 'children': ['314']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'macroNameInternal'}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '322']}, {'id': '317', 'type': 'attribute', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '322', 'type': 'argument_list', 'children': ['323']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'assignment', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'anyRegistered'}, {'id': '327', 'type': 'True', 'children': []}; {'id': '328', 'type': 'return_statement', 'children': ['329']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'macroName'}
def qteRegisterMacro(self, macroCls, replaceMacro: bool=False, macroName: str=None): if not issubclass(macroCls, QtmacsMacro): args = ('macroCls', 'class QtmacsMacro', inspect.stack()[0][3]) raise QtmacsArgumentError(*args) try: macroObj = macroCls() except Exception: msg = 'The macro <b>{}</b> has a faulty constructor.' msg = msg.format(macroCls.__name__) self.qteLogger.error(msg, stack_info=True) return None if macroName is None: if macroObj.qteMacroName() is None: macroName = self.qteMacroNameMangling(macroCls) else: macroName = macroObj.qteMacroName() macroObj._qteMacroName = macroName if len(macroObj.qteAppletSignature()) == 0: msg = 'Macro <b>{}</b> has no applet signatures.'.format(macroName) self.qteLogger.error(msg, stack_info=True) return None if len(macroObj.qteWidgetSignature()) == 0: msg = 'Macro <b>{}</b> has no widget signatures.'.format(macroName) self.qteLogger.error(msg, stack_info=True) return None anyRegistered = False for app_sig in macroObj.qteAppletSignature(): for wid_sig in macroObj.qteWidgetSignature(): macroNameInternal = (macroName, app_sig, wid_sig) if macroNameInternal in self._qteRegistryMacros: if replaceMacro: tmp = self._qteRegistryMacros.pop(macroNameInternal) msg = 'Replacing existing macro <b>{}</b> with new {}.' msg = msg.format(macroNameInternal, macroObj) self.qteLogger.info(msg) tmp.deleteLater() else: msg = 'Macro <b>{}</b> already exists (not replaced).' msg = msg.format(macroNameInternal) self.qteLogger.info(msg) continue self._qteRegistryMacros[macroNameInternal] = macroObj msg = ('Macro <b>{}</b> successfully registered.' .format(macroNameInternal)) self.qteLogger.info(msg) anyRegistered = True return macroName
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteGetMacroObject'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'macroName'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '9', 'type': 'typed_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'QWidget'}, {'id': '15', 'type': 'block', 'children': ['16', '94', '110', '126', '163']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '22', '62']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'_qteAdmin'"}; {'id': '22', 'type': 'block', 'children': ['23', '31', '39']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'app_signature'}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'appletSignature'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'wid_signature'}; {'id': '34', 'type': 'attribute', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'widgetSignature'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '43']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'app_signature'}; {'id': '42', 'type': 'None', 'children': []}, {'id': '43', 'type': 'block', 'children': ['44', '48', '60']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'Applet has no signature.'"}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'stack_info'}, {'id': '59', 'type': 'True', 'children': []}; {'id': '60', 'type': 'return_statement', 'children': ['61']}, {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'else_clause', 'children': ['63']}, {'id': '63', 'type': 'block', 'children': ['64', '68', '75']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'wid_signature'}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'qteGetAppletFromWidget'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '75', 'type': 'if_statement', 'children': ['76', '79', '84']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'is'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '78', 'type': 'None', 'children': []}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'app_signature'}, {'id': '83', 'type': 'None', 'children': []}; {'id': '84', 'type': 'else_clause', 'children': ['85']}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'app_signature'}, {'id': '89', 'type': 'attribute', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'appletSignature'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'name_match'}, {'id': '97', 'type': 'list_comprehension', 'children': ['98', '99', '104']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '99', 'type': 'for_in_clause', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': '_qteRegistryMacros'}; {'id': '104', 'type': 'if_clause', 'children': ['105']}, {'id': '105', 'type': 'comparison_operator', 'children': ['106', '109'], 'value': '=='}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'app_sig_match'}, {'id': '113', 'type': 'list_comprehension', 'children': ['114', '115', '118']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '115', 'type': 'for_in_clause', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'name_match'}; {'id': '118', 'type': 'if_clause', 'children': ['119']}, {'id': '119', 'type': 'comparison_operator', 'children': ['120', '123'], 'value': 'in'}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '123', 'type': 'tuple', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'app_signature'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '126', 'type': 'if_statement', 'children': ['127', '130', '145']}, {'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'wid_signature'}, {'id': '129', 'type': 'None', 'children': []}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'wid_sig_match'}; {'id': '134', 'type': 'list_comprehension', 'children': ['135', '136', '139']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '136', 'type': 'for_in_clause', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'app_sig_match'}, {'id': '139', 'type': 'if_clause', 'children': ['140']}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '144'], 'value': '=='}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '145', 'type': 'else_clause', 'children': ['146']}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'wid_sig_match'}; {'id': '150', 'type': 'list_comprehension', 'children': ['151', '152', '155']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '152', 'type': 'for_in_clause', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'app_sig_match'}, {'id': '155', 'type': 'if_clause', 'children': ['156']}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '160'], 'value': 'in'}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '160', 'type': 'tuple', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'wid_signature'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '163', 'type': 'if_statement', 'children': ['164', '170', '173', '193']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '169'], 'value': '=='}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'wid_sig_match'}, {'id': '169', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '170', 'type': 'block', 'children': ['171']}, {'id': '171', 'type': 'return_statement', 'children': ['172']}; {'id': '172', 'type': 'None', 'children': []}, {'id': '173', 'type': 'elif_clause', 'children': ['174', '180']}; {'id': '174', 'type': 'comparison_operator', 'children': ['175', '179'], 'value': '=='}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'wid_sig_match'}, {'id': '179', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '180', 'type': 'block', 'children': ['181', '187']}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'wid_sig_match'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '187', 'type': 'return_statement', 'children': ['188']}; {'id': '188', 'type': 'subscript', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': '_qteRegistryMacros'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '193', 'type': 'else_clause', 'children': ['194']}; {'id': '194', 'type': 'block', 'children': ['195', '217', '237', '251', '271', '285', '305', '327', '347', '351']}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '198', 'type': 'list_comprehension', 'children': ['199', '200', '203']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '200', 'type': 'for_in_clause', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'wid_sig_match'}, {'id': '203', 'type': 'if_clause', 'children': ['204']}; {'id': '204', 'type': 'boolean_operator', 'children': ['205', '211'], 'value': 'and'}, {'id': '205', 'type': 'parenthesized_expression', 'children': ['206'], 'value': '()'}; {'id': '206', 'type': 'comparison_operator', 'children': ['207', '210'], 'value': '!='}, {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '209', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '211', 'type': 'parenthesized_expression', 'children': ['212'], 'value': '()'}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '216'], 'value': '!='}, {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '215', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '216', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '217', 'type': 'if_statement', 'children': ['218', '224']}; {'id': '218', 'type': 'comparison_operator', 'children': ['219', '223'], 'value': '>'}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '223', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '224', 'type': 'block', 'children': ['225', '231']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '230', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '231', 'type': 'return_statement', 'children': ['232']}; {'id': '232', 'type': 'subscript', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': '_qteRegistryMacros'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '240', 'type': 'list_comprehension', 'children': ['241', '242', '245']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '242', 'type': 'for_in_clause', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'wid_sig_match'}, {'id': '245', 'type': 'if_clause', 'children': ['246']}; {'id': '246', 'type': 'comparison_operator', 'children': ['247', '250'], 'value': '!='}, {'id': '247', 'type': 'subscript', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '249', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '250', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '251', 'type': 'if_statement', 'children': ['252', '258']}; {'id': '252', 'type': 'comparison_operator', 'children': ['253', '257'], 'value': '>'}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '257', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '258', 'type': 'block', 'children': ['259', '265']}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '264', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '265', 'type': 'return_statement', 'children': ['266']}; {'id': '266', 'type': 'subscript', 'children': ['267', '270']}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': '_qteRegistryMacros'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '274', 'type': 'list_comprehension', 'children': ['275', '276', '279']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '276', 'type': 'for_in_clause', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'wid_sig_match'}, {'id': '279', 'type': 'if_clause', 'children': ['280']}; {'id': '280', 'type': 'comparison_operator', 'children': ['281', '284'], 'value': '!='}, {'id': '281', 'type': 'subscript', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '283', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '284', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '285', 'type': 'if_statement', 'children': ['286', '292']}; {'id': '286', 'type': 'comparison_operator', 'children': ['287', '291'], 'value': '>'}, {'id': '287', 'type': 'call', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '291', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '292', 'type': 'block', 'children': ['293', '299']}, {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '296', 'type': 'subscript', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '298', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '299', 'type': 'return_statement', 'children': ['300']}; {'id': '300', 'type': 'subscript', 'children': ['301', '304']}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': '_qteRegistryMacros'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '308', 'type': 'list_comprehension', 'children': ['309', '310', '313']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '310', 'type': 'for_in_clause', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'wid_sig_match'}, {'id': '313', 'type': 'if_clause', 'children': ['314']}; {'id': '314', 'type': 'boolean_operator', 'children': ['315', '321'], 'value': 'and'}, {'id': '315', 'type': 'parenthesized_expression', 'children': ['316'], 'value': '()'}; {'id': '316', 'type': 'comparison_operator', 'children': ['317', '320'], 'value': '=='}, {'id': '317', 'type': 'subscript', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '319', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '320', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '321', 'type': 'parenthesized_expression', 'children': ['322'], 'value': '()'}; {'id': '322', 'type': 'comparison_operator', 'children': ['323', '326'], 'value': '=='}, {'id': '323', 'type': 'subscript', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '325', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '326', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '327', 'type': 'if_statement', 'children': ['328', '334']}; {'id': '328', 'type': 'comparison_operator', 'children': ['329', '333'], 'value': '>'}, {'id': '329', 'type': 'call', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '333', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '334', 'type': 'block', 'children': ['335', '341']}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'assignment', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '338', 'type': 'subscript', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '340', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '341', 'type': 'return_statement', 'children': ['342']}; {'id': '342', 'type': 'subscript', 'children': ['343', '346']}, {'id': '343', 'type': 'attribute', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': '_qteRegistryMacros'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '347', 'type': 'expression_statement', 'children': ['348']}; {'id': '348', 'type': 'assignment', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '350', 'type': 'string', 'children': [], 'value': "'No compatible macro found - should be impossible.'"}, {'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': 'self'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '358', 'type': 'argument_list', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '360', 'type': 'keyword_argument', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'stack_info'}
def qteGetMacroObject(self, macroName: str, widgetObj: QtGui.QWidget): if hasattr(widgetObj, '_qteAdmin'): app_signature = widgetObj._qteAdmin.appletSignature wid_signature = widgetObj._qteAdmin.widgetSignature if app_signature is None: msg = 'Applet has no signature.' self.qteLogger.error(msg, stack_info=True) return None else: wid_signature = None app = qteGetAppletFromWidget(widgetObj) if app is None: app_signature = None else: app_signature = app._qteAdmin.appletSignature name_match = [m for m in self._qteRegistryMacros if m[0] == macroName] app_sig_match = [_ for _ in name_match if _[1] in (app_signature, '*')] if wid_signature is None: wid_sig_match = [_ for _ in app_sig_match if _[2] == '*'] else: wid_sig_match = [_ for _ in app_sig_match if _[2] in (wid_signature, '*')] if len(wid_sig_match) == 0: return None elif len(wid_sig_match) == 1: match = wid_sig_match[0] return self._qteRegistryMacros[match] else: tmp = [match for match in wid_sig_match if (match[1] != '*') and (match[2] != '*')] if len(tmp) > 0: match = tmp[0] return self._qteRegistryMacros[match] tmp = [match for match in wid_sig_match if match[2] != '*'] if len(tmp) > 0: match = tmp[0] return self._qteRegistryMacros[match] tmp = [match for match in wid_sig_match if match[1] != '*'] if len(tmp) > 0: match = tmp[0] return self._qteRegistryMacros[match] tmp = [match for match in wid_sig_match if (match[1] == '*') and (match[2] == '*')] if len(tmp) > 0: match = tmp[0] return self._qteRegistryMacros[match] msg = 'No compatible macro found - should be impossible.' self.qteLogger.error(msg, stack_info=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteGetAllMacroNames'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_default_parameter', 'children': ['6', '7', '11']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'QWidget'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '26', '36', '46']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'macro_list'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'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': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_qteRegistryMacros'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'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': 'macro_list'}, {'id': '29', 'type': 'list_comprehension', 'children': ['30', '33']}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'macro_list'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'macro_list'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'macro_list'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50', '53']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'macro_list'}, {'id': '53', 'type': 'else_clause', 'children': ['54']}; {'id': '54', 'type': 'block', 'children': ['55', '69', '85']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'macro_list'}; {'id': '58', 'type': 'list_comprehension', 'children': ['59', '66']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'qteGetMacroObject'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'macroName'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}; {'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'macro_list'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'macro_list'}; {'id': '72', 'type': 'list_comprehension', 'children': ['73', '78', '81']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'qteMacroName'}, {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'for_in_clause', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'macro_list'}, {'id': '81', 'type': 'if_clause', 'children': ['82']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '84', 'type': 'None', 'children': []}, {'id': '85', 'type': 'return_statement', 'children': ['86']}
def qteGetAllMacroNames(self, widgetObj: QtGui.QWidget=None): macro_list = tuple(self._qteRegistryMacros.keys()) macro_list = [_[0] for _ in macro_list] macro_list = tuple(set(macro_list)) if widgetObj is None: return macro_list else: macro_list = [self.qteGetMacroObject(macroName, widgetObj) for macroName in macro_list] macro_list = [_.qteMacroName() for _ in macro_list if _ is not None] return macro_list
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteBindKeyGlobal'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keysequence'}; {'id': '6', 'type': 'typed_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '8', 'type': 'type', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '10', 'type': 'block', 'children': ['11', '18', '54', '64', '79']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'keysequence'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'QtmacsKeysequence'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'keysequence'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '26']}, {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'qteIsMacroRegistered'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '26', 'type': 'block', 'children': ['27', '31', '40', '52']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'Cannot globally bind key to unknown macro <b>{}</b>.'"}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'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': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'stack_info'}, {'id': '51', 'type': 'True', 'children': []}; {'id': '52', 'type': 'return_statement', 'children': ['53']}, {'id': '53', 'type': 'False', 'children': []}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '61']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_qteGlobalKeyMap'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'qteInsertKey'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'keysequence'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '64', 'type': 'for_statement', 'children': ['65', '66', '69']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_qteAppletList'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'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': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'qteBindKeyApplet'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77', '78']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'keysequence'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'macroName'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '79', 'type': 'return_statement', 'children': ['80']}
def qteBindKeyGlobal(self, keysequence, macroName: str): keysequence = QtmacsKeysequence(keysequence) if not self.qteIsMacroRegistered(macroName): msg = 'Cannot globally bind key to unknown macro <b>{}</b>.' msg = msg.format(macroName) self.qteLogger.error(msg, stack_info=True) return False self._qteGlobalKeyMap.qteInsertKey(keysequence, macroName) for app in self._qteAppletList: self.qteBindKeyApplet(keysequence, macroName, app) return True
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteRegisterApplet'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '6', 'type': 'typed_default_parameter', 'children': ['7', '8', '10']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'replaceApplet'}; {'id': '8', 'type': 'type', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '41', '47', '96', '102', '110', '124']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '19']}, {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'issubclass'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'QtmacsApplet'}, {'id': '19', 'type': 'block', 'children': ['20', '35']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '23', 'type': 'tuple', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'cls'"}, {'id': '25', 'type': 'string', 'children': [], 'value': "'class QtmacsApplet'"}; {'id': '26', 'type': 'subscript', 'children': ['27', '34']}, {'id': '27', 'type': 'subscript', 'children': ['28', '33']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'inspect'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'QtmacsArgumentError'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'list_splat', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '47', 'type': 'if_statement', 'children': ['48', '53']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'in'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_qteRegistryApplets'}, {'id': '53', 'type': 'block', 'children': ['54', '63']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'The original applet <b>{}</b>'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'class_name'}, {'id': '63', 'type': 'if_statement', 'children': ['64', '65', '79']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'replaceApplet'}, {'id': '65', 'type': 'block', 'children': ['66', '70']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'augmented_assignment', 'children': ['68', '69'], 'value': '+='}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '69', 'type': 'string', 'children': [], 'value': "' was redefined.'"}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '77']}; {'id': '72', 'type': 'attribute', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '79', 'type': 'else_clause', 'children': ['80']}; {'id': '80', 'type': 'block', 'children': ['81', '85', '94']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'augmented_assignment', 'children': ['83', '84'], 'value': '+='}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '84', 'type': 'string', 'children': [], 'value': "' was not redefined.'"}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'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': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '94', 'type': 'return_statement', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'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': 'cls'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': '__qteRegisterAppletInit__'}, {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '109']}; {'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': '_qteRegistryApplets'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'class_name'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'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': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'Applet <b>{}</b> now registered.'"}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '124', 'type': 'return_statement', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'class_name'}
def qteRegisterApplet(self, cls, replaceApplet: bool=False): if not issubclass(cls, QtmacsApplet): args = ('cls', 'class QtmacsApplet', inspect.stack()[0][3]) raise QtmacsArgumentError(*args) class_name = cls.__name__ if class_name in self._qteRegistryApplets: msg = 'The original applet <b>{}</b>'.format(class_name) if replaceApplet: msg += ' was redefined.' self.qteLogger.warning(msg) else: msg += ' was not redefined.' self.qteLogger.warning(msg) return class_name cls.__qteRegisterAppletInit__() self._qteRegistryApplets[class_name] = cls self.qteLogger.info('Applet <b>{}</b> now registered.' .format(class_name)) return class_name
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'start'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '16', '23', '119', '125', '130', '136', '195', '259']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '11', 'type': 'dictionary', 'children': []}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '15', 'type': 'dictionary', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'info_parts'}, {'id': '19', 'type': 'set', 'children': ['20', '21', '22']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'info'"}, {'id': '21', 'type': 'string', 'children': [], 'value': "'get-value'"}; {'id': '22', 'type': 'string', 'children': [], 'value': "'get_value'"}, {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '28']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '28', 'type': 'block', 'children': ['29', '41']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'parser_cmd'}; {'id': '32', 'type': 'call', 'children': ['33', '38']}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'parser_commands'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '49']}; {'id': '42', 'type': 'boolean_operator', 'children': ['43', '46'], 'value': 'or'}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'in'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'parser_cmd'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'in'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '49', 'type': 'block', 'children': ['50', '65', '79', '89', '99']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'kws'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'parser_cmd'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '71']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'kws'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'Namespace'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'kws'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'vars'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'kws'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'boolean_operator', 'children': ['87', '88'], 'value': 'or'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'main'"}, {'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': 'ret'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'dictionary_splat', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'kws'}, {'id': '99', 'type': 'if_statement', 'children': ['100', '103']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'not'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'info_parts'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '109']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '118']}, {'id': '113', 'type': 'attribute', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '118', 'type': 'argument_list', 'children': []}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': '_experiment'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'project_parts'}; {'id': '128', 'type': 'set', 'children': ['129']}, {'id': '129', 'type': 'string', 'children': [], 'value': "'setup'"}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'projectname'}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': '_projectname'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '156', '185']}, {'id': '137', 'type': 'parenthesized_expression', 'children': ['138'], 'value': '()'}; {'id': '138', 'type': 'boolean_operator', 'children': ['139', '149'], 'value': 'and'}, {'id': '139', 'type': 'boolean_operator', 'children': ['140', '143'], 'value': 'and'}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'is'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'projectname'}; {'id': '142', 'type': 'None', 'children': []}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'project_parts'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'intersection'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': 'in'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'projectname'}, {'id': '151', 'type': 'attribute', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'projects'}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '170']}, {'id': '159', 'type': 'attribute', 'children': ['160', '169']}; {'id': '160', 'type': 'subscript', 'children': ['161', '168']}, {'id': '161', 'type': 'subscript', 'children': ['162', '167']}; {'id': '162', 'type': 'attribute', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'projects'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'projectname'}; {'id': '168', 'type': 'string', 'children': [], 'value': "'timestamps'"}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'dictionary_comprehension', 'children': ['172', '177']}; {'id': '172', 'type': 'pair', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '177', 'type': 'for_in_clause', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'project_parts'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'intersection'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '185', 'type': 'elif_clause', 'children': ['186', '188']}; {'id': '186', 'type': 'not_operator', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'no_modification'}; {'id': '194', 'type': 'True', 'children': []}, {'id': '195', 'type': 'if_statement', 'children': ['196', '207']}; {'id': '196', 'type': 'boolean_operator', 'children': ['197', '200'], 'value': 'and'}, {'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': 'is'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '199', 'type': 'None', 'children': []}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': 'in'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'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': 'config'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'experiments'}, {'id': '207', 'type': 'block', 'children': ['208', '214', '235']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'projectname'}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'projectname'}; {'id': '214', 'type': 'try_statement', 'children': ['215', '231']}, {'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': 'ts'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'subscript', 'children': ['223', '230']}, {'id': '223', 'type': 'subscript', 'children': ['224', '229']}; {'id': '224', 'type': 'attribute', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'projects'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'projectname'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'timestamps'"}, {'id': '231', 'type': 'except_clause', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'pass_statement', 'children': []}, {'id': '235', 'type': 'if_statement', 'children': ['236', '243']}; {'id': '236', 'type': 'not_operator', 'children': ['237']}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'is_archived'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '257']}; {'id': '246', 'type': 'attribute', 'children': ['247', '256']}, {'id': '247', 'type': 'subscript', 'children': ['248', '255']}; {'id': '248', 'type': 'subscript', 'children': ['249', '254']}, {'id': '249', 'type': 'attribute', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'experiments'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '255', 'type': 'string', 'children': [], 'value': "'timestamps'"}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '259', 'type': 'return_statement', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'Namespace'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'dictionary_splat', 'children': ['264']}
def start(self, **kwargs): ts = {} ret = {} info_parts = {'info', 'get-value', 'get_value'} for cmd in self.commands: parser_cmd = self.parser_commands.get(cmd, cmd) if parser_cmd in kwargs or cmd in kwargs: kws = kwargs.get(cmd, kwargs.get(parser_cmd)) if isinstance(kws, Namespace): kws = vars(kws) func = getattr(self, cmd or 'main') ret[cmd] = func(**kws) if cmd not in info_parts: ts[cmd] = str(dt.datetime.now()) exp = self._experiment project_parts = {'setup'} projectname = self._projectname if (projectname is not None and project_parts.intersection(ts) and projectname in self.config.projects): self.config.projects[projectname]['timestamps'].update( {key: ts[key] for key in project_parts.intersection(ts)}) elif not ts: self.no_modification = True if exp is not None and exp in self.config.experiments: projectname = self.projectname try: ts.update(self.config.projects[projectname]['timestamps']) except KeyError: pass if not self.is_archived(exp): self.config.experiments[exp]['timestamps'].update(ts) return Namespace(**ret)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'app_main'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'experiment'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'new'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'verbosity_level'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'no_modification'}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '94', '151', '189', '223']}, {'id': '27', 'type': 'if_statement', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '29', 'type': 'block', 'children': ['30', '39', '56', '88']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'patt'}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'compile'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'experiment'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'patt'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'search'}, {'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': 'config'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'experiments'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '63', '73']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '62'], 'value': '>'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '1'}, {'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': 'binary_operator', 'children': ['69', '70'], 'value': '%'}, {'id': '69', 'type': 'string', 'children': [], 'value': '"Found multiple matches for %s: %s"'}; {'id': '70', 'type': 'tuple', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '73', 'type': 'elif_clause', 'children': ['74', '80']}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '79'], 'value': '=='}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'raise_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '%'}; {'id': '86', 'type': 'string', 'children': [], 'value': '"No experiment matches %s"'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'experiment'}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '102', '109', '143']}, {'id': '95', 'type': 'boolean_operator', 'children': ['96', '97'], 'value': 'and'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'last'}, {'id': '97', 'type': 'attribute', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'experiments'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '108', 'type': 'None', 'children': []}, {'id': '109', 'type': 'elif_clause', 'children': ['110', '117']}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '112'], 'value': 'and'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '112', 'type': 'attribute', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'experiments'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'try_statement', 'children': ['119', '133']}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'experiment'}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'get_next_name'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'experiment'}, {'id': '133', 'type': 'except_clause', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'raise_statement', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'concatenated_string', 'children': ['141', '142']}, {'id': '141', 'type': 'string', 'children': [], 'value': '"Could not estimate an experiment id! Please use the "'}; {'id': '142', 'type': 'string', 'children': [], 'value': '"experiment argument to provide an id."'}, {'id': '143', 'type': 'else_clause', 'children': ['144']}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': '_experiment'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'experiment'}, {'id': '151', 'type': 'if_statement', 'children': ['152', '153', '160']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'DEBUG'}; {'id': '160', 'type': 'elif_clause', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'verbosity_level'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'if_statement', 'children': ['164', '171', '180']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'in'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'verbosity_level'}; {'id': '166', 'type': 'list', 'children': ['167', '168', '169', '170'], 'value': "['DEBUG', 'INFO', 'WARNING', 'ERROR']"}, {'id': '167', 'type': 'string', 'children': [], 'value': "'DEBUG'"}; {'id': '168', 'type': 'string', 'children': [], 'value': "'INFO'"}, {'id': '169', 'type': 'string', 'children': [], 'value': "'WARNING'"}; {'id': '170', 'type': 'string', 'children': [], 'value': "'ERROR'"}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '177', 'type': 'argument_list', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'verbosity_level'}; {'id': '180', 'type': 'else_clause', 'children': ['181']}, {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'verbosity_level'}, {'id': '189', 'type': 'if_statement', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '191', 'type': 'block', 'children': ['192', '214']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '212']}; {'id': '194', 'type': 'attribute', 'children': ['195', '211']}, {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'getLogger'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'get_toplevel_module'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'getmodule'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'setLevel'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '221']}; {'id': '216', 'type': 'attribute', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'setLevel'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'no_modification'}
def app_main(self, experiment=None, last=False, new=False, verbose=False, verbosity_level=None, no_modification=False, match=False): if match: patt = re.compile(experiment) matches = list(filter(patt.search, self.config.experiments)) if len(matches) > 1: raise ValueError("Found multiple matches for %s: %s" % ( experiment, matches)) elif len(matches) == 0: raise ValueError("No experiment matches %s" % experiment) experiment = matches[0] if last and self.config.experiments: self.experiment = None elif new and self.config.experiments: try: self.experiment = utils.get_next_name(self.experiment) except ValueError: raise ValueError( "Could not estimate an experiment id! Please use the " "experiment argument to provide an id.") else: self._experiment = experiment if verbose: verbose = logging.DEBUG elif verbosity_level: if verbosity_level in ['DEBUG', 'INFO', 'WARNING', 'ERROR']: verbose = getattr(logging, verbosity_level) else: verbose = int(verbosity_level) if verbose: logging.getLogger( utils.get_toplevel_module(inspect.getmodule(self))).setLevel( verbose) self.logger.setLevel(verbose) self.no_modification = no_modification
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'configure'}, {'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': 'global_config'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'project_config'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ifile'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'forcing'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'serial'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'nprocs'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'update_from'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'dictionary_splat_pattern', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '28', 'type': 'block', 'children': ['29', '77', '93', '109', '137', '145']}, {'id': '29', 'type': 'if_statement', 'children': ['30', '31', '40', '63']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'global_config'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'd'}, {'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': 'config'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'global_config'}; {'id': '40', 'type': 'elif_clause', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'project_config'}; {'id': '42', 'type': 'block', 'children': ['43', '51']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'app_main'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'dictionary_splat', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '54', 'type': 'subscript', 'children': ['55', '60']}, {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'projects'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'projectname'}, {'id': '63', 'type': 'else_clause', 'children': ['64']}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '68', 'type': 'subscript', 'children': ['69', '74']}, {'id': '69', 'type': 'attribute', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'experiments'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'experiment'}, {'id': '77', 'type': 'if_statement', 'children': ['78', '81']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'is'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'ifile'}; {'id': '80', 'type': 'None', 'children': []}, {'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': 'd'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'input'"}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'osp'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'abspath'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'ifile'}, {'id': '93', 'type': 'if_statement', 'children': ['94', '97']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'is'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'forcing'}; {'id': '96', 'type': 'None', 'children': []}, {'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': 'd'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'forcing'"}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'osp'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'abspath'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'forcing'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '113']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'update_from'}; {'id': '112', 'type': 'None', 'children': []}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'with_statement', 'children': ['115', '124']}, {'id': '115', 'type': 'with_clause', 'children': ['116']}; {'id': '116', 'type': 'with_item', 'children': ['117']}, {'id': '117', 'type': 'as_pattern', 'children': ['118', '122']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'string', 'children': [], 'value': "'update_from'"}; {'id': '122', 'type': 'as_pattern_target', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'update'}; {'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': 'yaml'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'load'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'global_config'}; {'id': '140', 'type': 'attribute', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'global_config'}, {'id': '145', 'type': 'if_statement', 'children': ['146', '147', '154']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'serial'}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '153']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'global_config'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'serial'"}, {'id': '153', 'type': 'True', 'children': []}; {'id': '154', 'type': 'elif_clause', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'nprocs'}; {'id': '156', 'type': 'block', 'children': ['157', '169', '175']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'nprocs'}; {'id': '160', 'type': 'conditional_expression', 'children': ['161', '165', '168'], 'value': 'if'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'nprocs'}, {'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '!='}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'nprocs'}, {'id': '167', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'nprocs'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '174']}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'global_config'}, {'id': '173', 'type': 'string', 'children': [], 'value': "'serial'"}; {'id': '174', 'type': 'False', 'children': []}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '180']}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'global_config'}, {'id': '179', 'type': 'string', 'children': [], 'value': "'nprocs'"}
def configure(self, global_config=False, project_config=False, ifile=None, forcing=None, serial=False, nprocs=None, update_from=None, **kwargs): if global_config: d = self.config.global_config elif project_config: self.app_main(**kwargs) d = self.config.projects[self.projectname] else: d = self.config.experiments[self.experiment] if ifile is not None: d['input'] = osp.abspath(ifile) if forcing is not None: d['forcing'] = osp.abspath(forcing) if update_from is not None: with open('update_from') as f: d.update(yaml.load(f)) global_config = self.config.global_config if serial: global_config['serial'] = True elif nprocs: nprocs = int(nprocs) if nprocs != 'all' else nprocs global_config['serial'] = False global_config['nprocs'] = nprocs
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_basic_type_docs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'existing_types'}; {'id': '6', 'type': 'block', 'children': ['7', '133', '137', '325', '347', '354']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'raml_built_in_types'}; {'id': '10', 'type': 'dictionary', 'children': ['11', '17', '23', '33', '39', '49', '55', '65', '77', '83', '89', '99', '105', '111', '117', '123']}, {'id': '11', 'type': 'pair', 'children': ['12', '13']}; {'id': '12', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '13', 'type': 'dictionary', 'children': ['14']}; {'id': '14', 'type': 'pair', 'children': ['15', '16']}, {'id': '15', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'pair', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': '"time-only"'}, {'id': '19', 'type': 'dictionary', 'children': ['20']}; {'id': '20', 'type': 'pair', 'children': ['21', '22']}, {'id': '21', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '22', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '23', 'type': 'pair', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"datetime"'}, {'id': '25', 'type': 'dictionary', 'children': ['26', '29']}; {'id': '26', 'type': 'pair', 'children': ['27', '28']}, {'id': '27', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '28', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '29', 'type': 'pair', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': '"pale_children"'}, {'id': '31', 'type': 'list', 'children': ['32'], 'value': '["timestamp"]'}; {'id': '32', 'type': 'string', 'children': [], 'value': '"timestamp"'}, {'id': '33', 'type': 'pair', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': '"datetime-only"'}, {'id': '35', 'type': 'dictionary', 'children': ['36']}; {'id': '36', 'type': 'pair', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '39', 'type': 'pair', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': '"date-only"'}, {'id': '41', 'type': 'dictionary', 'children': ['42', '45']}; {'id': '42', 'type': 'pair', 'children': ['43', '44']}, {'id': '43', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '44', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '45', 'type': 'pair', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"pale_children"'}, {'id': '47', 'type': 'list', 'children': ['48'], 'value': '["date"]'}; {'id': '48', 'type': 'string', 'children': [], 'value': '"date"'}, {'id': '49', 'type': 'pair', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"number"'}, {'id': '51', 'type': 'dictionary', 'children': ['52']}; {'id': '52', 'type': 'pair', 'children': ['53', '54']}, {'id': '53', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '55', 'type': 'pair', 'children': ['56', '57']}; {'id': '56', 'type': 'string', 'children': [], 'value': '"boolean"'}, {'id': '57', 'type': 'dictionary', 'children': ['58', '61']}; {'id': '58', 'type': 'pair', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '60', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '61', 'type': 'pair', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': '"pale_children"'}, {'id': '63', 'type': 'list', 'children': ['64'], 'value': '["boolean"]'}; {'id': '64', 'type': 'string', 'children': [], 'value': '"boolean"'}, {'id': '65', 'type': 'pair', 'children': ['66', '67']}; {'id': '66', 'type': 'string', 'children': [], 'value': '"string"'}, {'id': '67', 'type': 'dictionary', 'children': ['68', '71']}; {'id': '68', 'type': 'pair', 'children': ['69', '70']}, {'id': '69', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '70', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '71', 'type': 'pair', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': '"pale_children"'}, {'id': '73', 'type': 'list', 'children': ['74', '75', '76'], 'value': '["url", "string", "uri"]'}; {'id': '74', 'type': 'string', 'children': [], 'value': '"url"'}, {'id': '75', 'type': 'string', 'children': [], 'value': '"string"'}; {'id': '76', 'type': 'string', 'children': [], 'value': '"uri"'}, {'id': '77', 'type': 'pair', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': '"null"'}, {'id': '79', 'type': 'dictionary', 'children': ['80']}; {'id': '80', 'type': 'pair', 'children': ['81', '82']}, {'id': '81', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '82', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '83', 'type': 'pair', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"file"'}, {'id': '85', 'type': 'dictionary', 'children': ['86']}; {'id': '86', 'type': 'pair', 'children': ['87', '88']}, {'id': '87', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '89', 'type': 'pair', 'children': ['90', '91']}; {'id': '90', 'type': 'string', 'children': [], 'value': '"array"'}, {'id': '91', 'type': 'dictionary', 'children': ['92', '95']}; {'id': '92', 'type': 'pair', 'children': ['93', '94']}, {'id': '93', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '94', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '95', 'type': 'pair', 'children': ['96', '97']}; {'id': '96', 'type': 'string', 'children': [], 'value': '"pale_children"'}, {'id': '97', 'type': 'list', 'children': ['98'], 'value': '["list"]'}; {'id': '98', 'type': 'string', 'children': [], 'value': '"list"'}, {'id': '99', 'type': 'pair', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': '"object"'}, {'id': '101', 'type': 'dictionary', 'children': ['102']}; {'id': '102', 'type': 'pair', 'children': ['103', '104']}, {'id': '103', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '104', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '105', 'type': 'pair', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': '"union"'}, {'id': '107', 'type': 'dictionary', 'children': ['108']}; {'id': '108', 'type': 'pair', 'children': ['109', '110']}, {'id': '109', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '110', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '111', 'type': 'pair', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': '"XSD Schema"'}, {'id': '113', 'type': 'dictionary', 'children': ['114']}; {'id': '114', 'type': 'pair', 'children': ['115', '116']}, {'id': '115', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '116', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '117', 'type': 'pair', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': '"JSON Schema"'}, {'id': '119', 'type': 'dictionary', 'children': ['120']}; {'id': '120', 'type': 'pair', 'children': ['121', '122']}, {'id': '121', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '122', 'type': 'string', 'children': [], 'value': '"any"'}, {'id': '123', 'type': 'pair', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': '"integer"'}, {'id': '125', 'type': 'dictionary', 'children': ['126', '129']}; {'id': '126', 'type': 'pair', 'children': ['127', '128']}, {'id': '127', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '128', 'type': 'string', 'children': [], 'value': '"number"'}, {'id': '129', 'type': 'pair', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': '"pale_children"'}, {'id': '131', 'type': 'list', 'children': ['132'], 'value': '["integer"]'}; {'id': '132', 'type': 'string', 'children': [], 'value': '"integer"'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'basic_types'}; {'id': '136', 'type': 'dictionary', 'children': []}, {'id': '137', 'type': 'for_statement', 'children': ['138', '139', '140']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'if_statement', 'children': ['142', '147']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '146', 'type': 'string', 'children': [], 'value': '"value_type"'}, {'id': '147', 'type': 'block', 'children': ['148', '160']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '151', 'type': 'call', 'children': ['152', '157']}; {'id': '152', 'type': 'attribute', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'value_type'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '159']}; {'id': '158', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '159', 'type': 'string', 'children': [], 'value': '"_"'}; {'id': '160', 'type': 'if_statement', 'children': ['161', '174']}, {'id': '161', 'type': 'boolean_operator', 'children': ['162', '170', '171'], 'value': 'and'}; {'id': '162', 'type': 'boolean_operator', 'children': ['163', '166', '167'], 'value': 'and'}, {'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': 'not'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'raml_built_in_types'}; {'id': '166', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'not'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'basic_types'}; {'id': '170', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'not'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'existing_types'}; {'id': '174', 'type': 'block', 'children': ['175', '181', '205']}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '180']}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'basic_types'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'type_name'}; {'id': '180', 'type': 'dictionary', 'children': []}, {'id': '181', 'type': 'if_statement', 'children': ['182', '187']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '186', 'type': 'string', 'children': [], 'value': '"__doc__"'}, {'id': '187', 'type': 'block', 'children': ['188', '197']}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'modified_description'}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'clean_description'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '__doc__'}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '204']}, {'id': '199', 'type': 'subscript', 'children': ['200', '203']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'basic_types'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '203', 'type': 'string', 'children': [], 'value': '"description"'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'modified_description'}, {'id': '205', 'type': 'for_statement', 'children': ['206', '207', '208']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'raml_type'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'raml_built_in_types'}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'if_statement', 'children': ['210', '215', '234']}; {'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': 'in'}, {'id': '211', 'type': 'string', 'children': [], 'value': '"pale_children"'}; {'id': '212', 'type': 'subscript', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'raml_built_in_types'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'raml_type'}, {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'if_statement', 'children': ['217', '224']}, {'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': 'in'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '219', 'type': 'subscript', 'children': ['220', '223']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'raml_built_in_types'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'raml_type'}, {'id': '223', 'type': 'string', 'children': [], 'value': '"pale_children"'}; {'id': '224', 'type': 'block', 'children': ['225', '233']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '232']}, {'id': '227', 'type': 'subscript', 'children': ['228', '231']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'basic_types'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '231', 'type': 'string', 'children': [], 'value': '"type"'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'raml_type'}, {'id': '233', 'type': 'break_statement', 'children': []}; {'id': '234', 'type': 'else_clause', 'children': ['235']}, {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'if_statement', 'children': ['237', '246', '288']}, {'id': '237', 'type': 'boolean_operator', 'children': ['238', '243'], 'value': 'and'}; {'id': '238', 'type': 'call', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '240', 'type': 'argument_list', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '242', 'type': 'string', 'children': [], 'value': '"is_list"'}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'is_list'}; {'id': '246', 'type': 'block', 'children': ['247', '255']}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '254']}, {'id': '249', 'type': 'subscript', 'children': ['250', '253']}; {'id': '250', 'type': 'subscript', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'basic_types'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '253', 'type': 'string', 'children': [], 'value': '"type"'}; {'id': '254', 'type': 'string', 'children': [], 'value': '"array"'}, {'id': '255', 'type': 'if_statement', 'children': ['256', '267', '278']}; {'id': '256', 'type': 'boolean_operator', 'children': ['257', '262'], 'value': 'and'}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '259', 'type': 'argument_list', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '261', 'type': 'string', 'children': [], 'value': '"list_item_type"'}; {'id': '262', 'type': 'comparison_operator', 'children': ['263', '266'], 'value': '!='}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'list_item_type'}; {'id': '266', 'type': 'None', 'children': []}, {'id': '267', 'type': 'block', 'children': ['268']}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'assignment', 'children': ['270', '275']}; {'id': '270', 'type': 'subscript', 'children': ['271', '274']}, {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'basic_types'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'type_name'}; {'id': '274', 'type': 'string', 'children': [], 'value': '"items"'}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'list_item_type'}; {'id': '278', 'type': 'else_clause', 'children': ['279']}, {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '287']}; {'id': '282', 'type': 'subscript', 'children': ['283', '286']}, {'id': '283', 'type': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'basic_types'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'type_name'}; {'id': '286', 'type': 'string', 'children': [], 'value': '"items"'}, {'id': '287', 'type': 'string', 'children': [], 'value': '"base"'}; {'id': '288', 'type': 'else_clause', 'children': ['289']}, {'id': '289', 'type': 'block', 'children': ['290', '298']}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'assignment', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'pale_parent_class'}, {'id': '293', 'type': 'subscript', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': '__mro__'}, {'id': '297', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '298', 'type': 'if_statement', 'children': ['299', '304', '313']}, {'id': '299', 'type': 'comparison_operator', 'children': ['300', '303'], 'value': '=='}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'pale_parent_class'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '303', 'type': 'string', 'children': [], 'value': '"object"'}; {'id': '304', 'type': 'block', 'children': ['305']}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '312']}, {'id': '307', 'type': 'subscript', 'children': ['308', '311']}; {'id': '308', 'type': 'subscript', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'basic_types'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '311', 'type': 'string', 'children': [], 'value': '"type"'}; {'id': '312', 'type': 'string', 'children': [], 'value': '"object"'}, {'id': '313', 'type': 'else_clause', 'children': ['314']}; {'id': '314', 'type': 'block', 'children': ['315']}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'assignment', 'children': ['317', '322']}, {'id': '317', 'type': 'subscript', 'children': ['318', '321']}; {'id': '318', 'type': 'subscript', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'basic_types'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '321', 'type': 'string', 'children': [], 'value': '"type"'}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'pale_parent_class'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'value_type'}, {'id': '325', 'type': 'expression_statement', 'children': ['326']}; {'id': '326', 'type': 'assignment', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'ordered_basic_types'}; {'id': '328', 'type': 'call', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}, {'id': '331', 'type': 'call', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '333', 'type': 'argument_list', 'children': ['334', '339']}; {'id': '334', 'type': 'call', 'children': ['335', '338']}, {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'basic_types'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '338', 'type': 'argument_list', 'children': []}, {'id': '339', 'type': 'keyword_argument', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '341', 'type': 'lambda', 'children': ['342', '344']}; {'id': '342', 'type': 'lambda_parameters', 'children': ['343']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '344', 'type': 'subscript', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '346', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '347', 'type': 'expression_statement', 'children': ['348']}; {'id': '348', 'type': 'assignment', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'basic_docs'}; {'id': '350', 'type': 'call', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'generate_type_docs'}; {'id': '352', 'type': 'argument_list', 'children': ['353']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'ordered_basic_types'}; {'id': '354', 'type': 'return_statement', 'children': ['355']}, {'id': '355', 'type': 'tuple', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'basic_docs'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'basic_types'}
def generate_basic_type_docs(fields, existing_types): raml_built_in_types = { "any": { "parent": None, }, "time-only": { "parent": "any", }, "datetime": { "parent": "any", "pale_children": ["timestamp"], }, "datetime-only": { "parent": "any", }, "date-only": { "parent": "any", "pale_children": ["date"], }, "number": { "parent": "any", }, "boolean": { "parent": "any", "pale_children": ["boolean"] }, "string": { "parent": "any", "pale_children": ["url", "string", "uri"], }, "null": { "parent": "any", }, "file": { "parent": "any", }, "array": { "parent": "any", "pale_children": ["list"], }, "object": { "parent": "any", }, "union": { "parent": "any", }, "XSD Schema": { "parent": "any", }, "JSON Schema": { "parent": "any", }, "integer": { "parent": "number", "pale_children": ["integer"], }, } basic_types = {} for field in fields: if hasattr(field, "value_type"): type_name = field.value_type.replace(" ", "_") if type_name not in raml_built_in_types \ and type_name not in basic_types \ and type_name not in existing_types: basic_types[type_name] = {} if hasattr(field, "__doc__"): modified_description = clean_description(field.__doc__) basic_types[type_name]["description"] = modified_description for raml_type in raml_built_in_types: if "pale_children" in raml_built_in_types[raml_type]: if type_name in raml_built_in_types[raml_type]["pale_children"]: basic_types[type_name]["type"] = raml_type break else: if hasattr(field, "is_list") and field.is_list: basic_types[type_name]["type"] = "array" if hasattr(field, "list_item_type") and field.list_item_type != None: basic_types[type_name]["items"] = field.list_item_type else: basic_types[type_name]["items"] = "base" else: pale_parent_class = field.__mro__[1] if pale_parent_class.__name__ == "object": basic_types[type_name]["type"] = "object" else: basic_types[type_name]["type"] = pale_parent_class.value_type ordered_basic_types = OrderedDict(sorted(basic_types.items(), key=lambda t: t[0])) basic_docs = generate_type_docs(ordered_basic_types) return (basic_docs, basic_types)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_doc_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '27', '34', '50', '54', '98', '105', '121']}, {'id': '7', 'type': 'import_from_statement', 'children': ['8', '10', '12', '14']}; {'id': '8', 'type': 'dotted_name', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'pale'}; {'id': '10', 'type': 'dotted_name', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'extract_endpoints'}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'extract_resources'}; {'id': '14', 'type': 'dotted_name', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'is_pale_module'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '22']}, {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'is_pale_module'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'raise_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'module_endpoints'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'extract_endpoints'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ep_doc'}, {'id': '37', 'type': 'dictionary_comprehension', 'children': ['38', '46']}; {'id': '38', 'type': 'pair', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ep'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_route_name'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'document_endpoint'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ep'}; {'id': '46', 'type': 'for_in_clause', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ep'}; {'id': '48', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'module_endpoints'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ep_doc_filtered'}, {'id': '53', 'type': 'dictionary', 'children': []}; {'id': '54', 'type': 'for_statement', 'children': ['55', '56', '57']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'endpoint'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ep_doc'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'if_statement', 'children': ['59', '89']}, {'id': '59', 'type': 'boolean_operator', 'children': ['60', '78', '79'], 'value': 'or'}; {'id': '60', 'type': 'boolean_operator', 'children': ['61', '75'], 'value': 'and'}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '72'], 'value': 'and'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '71'], 'value': '!='}, {'id': '63', 'type': 'call', 'children': ['64', '69']}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ep_doc'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'endpoint'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'string', 'children': [], 'value': '"requires_permission"'}, {'id': '71', 'type': 'None', 'children': []}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': '!='}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '74', 'type': 'None', 'children': []}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'is_admin'}; {'id': '78', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '88'], 'value': '=='}; {'id': '80', 'type': 'call', 'children': ['81', '86']}, {'id': '81', 'type': 'attribute', 'children': ['82', '85']}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ep_doc'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'endpoint'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'string', 'children': [], 'value': '"requires_permission"'}; {'id': '88', 'type': 'None', 'children': []}, {'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': 'ep_doc_filtered'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'endpoint'}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'ep_doc'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'endpoint'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'module_resources'}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'extract_resources'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'res_doc'}; {'id': '108', 'type': 'dictionary_comprehension', 'children': ['109', '117']}, {'id': '109', 'type': 'pair', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': '_value_type'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'document_resource'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '117', 'type': 'for_in_clause', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '119', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'module_resources'}, {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'dictionary', 'children': ['123', '126']}, {'id': '123', 'type': 'pair', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'endpoints'"}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ep_doc_filtered'}; {'id': '126', 'type': 'pair', 'children': ['127', '128']}, {'id': '127', 'type': 'string', 'children': [], 'value': "'resources'"}
def generate_doc_dict(module, user): from pale import extract_endpoints, extract_resources, is_pale_module if not is_pale_module(module): raise ValueError( ) module_endpoints = extract_endpoints(module) ep_doc = { ep._route_name: document_endpoint(ep) for ep \ in module_endpoints } ep_doc_filtered = {} for endpoint in ep_doc: if ep_doc[endpoint].get("requires_permission") != None and user != None and user.is_admin or \ ep_doc[endpoint].get("requires_permission") == None: ep_doc_filtered[endpoint] = ep_doc[endpoint] module_resources = extract_resources(module) res_doc = { r._value_type: document_resource(r) for r \ in module_resources } return {'endpoints': ep_doc_filtered, 'resources': res_doc}
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_driver'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'desired_capabilities'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '15', '26', '33', '41', '45', '333', '371', '380']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'override_caps'}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '14'], 'value': 'or'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'desired_capabilities'}; {'id': '14', 'type': 'dictionary', 'children': []}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18', '19']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'desired_capabilities'}; {'id': '18', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'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': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'make_selenium_desired_capabilities'}, {'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': 'desired_capabilities'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'override_caps'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'browser_string'}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'browser'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'chromedriver_version'}; {'id': '44', 'type': 'None', 'children': []}, {'id': '45', 'type': 'if_statement', 'children': ['46', '49', '100']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'remote'}, {'id': '49', 'type': 'block', 'children': ['50', '61']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'driver'}, {'id': '53', 'type': 'call', 'children': ['54', '59']}; {'id': '54', 'type': 'attribute', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'remote_service'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'build_driver'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'desired_capabilities'}, {'id': '61', 'type': 'if_statement', 'children': ['62', '74']}; {'id': '62', 'type': 'boolean_operator', 'children': ['63', '66', '67'], 'value': 'and'}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '=='}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'browser_string'}, {'id': '65', 'type': 'string', 'children': [], 'value': '"CHROME"'}; {'id': '66', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '73'], 'value': '=='}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'remote_service'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '73', 'type': 'string', 'children': [], 'value': '"saucelabs"'}; {'id': '74', 'type': 'block', 'children': ['75', '86']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'chromedriver_version'}; {'id': '78', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'desired_capabilities'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"chromedriver-version"'}, {'id': '85', 'type': 'None', 'children': []}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'chromedriver_version'}, {'id': '89', 'type': 'None', 'children': []}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'raise_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'concatenated_string', 'children': ['96', '97', '98', '99']}; {'id': '96', 'type': 'string', 'children': [], 'value': '"when using Chrome, you must set a "'}, {'id': '97', 'type': 'string', 'children': [], 'value': '"``chromedriver-version`` capability so that Selenic "'}; {'id': '98', 'type': 'string', 'children': [], 'value': '"can detect which version of Chromedriver will "'}, {'id': '99', 'type': 'string', 'children': [], 'value': '"be used."'}; {'id': '100', 'type': 'else_clause', 'children': ['101']}, {'id': '101', 'type': 'block', 'children': ['102', '272', '281', '295', '317']}; {'id': '102', 'type': 'if_statement', 'children': ['103', '106', '187', '237', '250', '263']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '=='}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'browser_string'}, {'id': '105', 'type': 'string', 'children': [], 'value': '"CHROME"'}; {'id': '106', 'type': 'block', 'children': ['107', '115', '154', '165', '180']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'chromedriver_path'}; {'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': 'local_conf'}; {'id': '114', 'type': 'string', 'children': [], 'value': '"CHROMEDRIVER_PATH"'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'driver'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'webdriver'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'Chrome'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124', '134', '137', '144']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'chromedriver_path'}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'chrome_options'}; {'id': '126', 'type': 'call', 'children': ['127', '132']}, {'id': '127', 'type': 'attribute', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'local_conf'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'string', 'children': [], 'value': '"CHROME_OPTIONS"'}; {'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'desired_capabilities'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'desired_capabilities'}, {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'service_log_path'}, {'id': '139', 'type': 'subscript', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'local_conf'}, {'id': '143', 'type': 'string', 'children': [], 'value': '"SERVICE_LOG_PATH"'}; {'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'service_args'}; {'id': '146', 'type': 'call', 'children': ['147', '152']}, {'id': '147', 'type': 'attribute', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'local_conf'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'string', 'children': [], 'value': '"SERVICE_ARGS"'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'version_line'}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'check_output'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'list', 'children': ['163', '164'], 'value': '[chromedriver_path, "--version"]'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'chromedriver_path'}; {'id': '164', 'type': 'string', 'children': [], 'value': '"--version"'}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'version_str'}; {'id': '168', 'type': 'call', 'children': ['169', '178']}, {'id': '169', 'type': 'attribute', 'children': ['170', '177']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '176']}, {'id': '175', 'type': 'string', 'children': [], 'value': 'ur"^ChromeDriver (\\d+\\.\\d+)"'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'version_line'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'chromedriver_version'}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'StrictVersion'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'version_str'}, {'id': '187', 'type': 'elif_clause', 'children': ['188', '191']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': '=='}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'browser_string'}; {'id': '190', 'type': 'string', 'children': [], 'value': '"FIREFOX"'}, {'id': '191', 'type': 'block', 'children': ['192', '208', '224']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '195', 'type': 'boolean_operator', 'children': ['196', '204', '205'], 'value': 'or'}; {'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': 'local_conf'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'string', 'children': [], 'value': '"FIREFOX_PROFILE"'}; {'id': '204', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'FirefoxProfile'}, {'id': '207', 'type': 'argument_list', 'children': []}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'binary'}, {'id': '211', 'type': 'boolean_operator', 'children': ['212', '220', '221'], 'value': 'or'}; {'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': 'self'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'local_conf'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'string', 'children': [], 'value': '"FIREFOX_BINARY"'}; {'id': '220', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '221', 'type': 'call', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'FirefoxBinary'}, {'id': '223', 'type': 'argument_list', 'children': []}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'driver'}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'webdriver'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'Firefox'}, {'id': '231', 'type': 'argument_list', 'children': ['232', '233', '234']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'binary'}; {'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'capabilities'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'desired_capabilities'}, {'id': '237', 'type': 'elif_clause', 'children': ['238', '241']}; {'id': '238', 'type': 'comparison_operator', 'children': ['239', '240'], 'value': '=='}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'browser_string'}; {'id': '240', 'type': 'string', 'children': [], 'value': '"INTERNETEXPLORER"'}, {'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': 'driver'}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'webdriver'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'Ie'}, {'id': '249', 'type': 'argument_list', 'children': []}; {'id': '250', 'type': 'elif_clause', 'children': ['251', '254']}, {'id': '251', 'type': 'comparison_operator', 'children': ['252', '253'], 'value': '=='}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'browser_string'}, {'id': '253', 'type': 'string', 'children': [], 'value': '"OPERA"'}; {'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': 'driver'}; {'id': '258', 'type': 'call', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'webdriver'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'Opera'}; {'id': '262', 'type': 'argument_list', 'children': []}, {'id': '263', 'type': 'else_clause', 'children': ['264']}; {'id': '264', 'type': 'block', 'children': ['265']}, {'id': '265', 'type': 'raise_statement', 'children': ['266']}; {'id': '266', 'type': 'call', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'binary_operator', 'children': ['270', '271'], 'value': '+'}; {'id': '270', 'type': 'string', 'children': [], 'value': '"can\'t start a local "'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'browser_string'}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'driver_caps'}, {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'NormalizedCapabilities'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'driver'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'desired_capabilities'}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '284', '285']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'browser_version'}; {'id': '284', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '285', 'type': 'call', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '289', 'type': 'argument_list', 'children': ['290', '291', '292']}; {'id': '290', 'type': 'string', 'children': [], 'value': 'r"\\..*$"'}, {'id': '291', 'type': 'string', 'children': [], 'value': '""'}; {'id': '292', 'type': 'subscript', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'driver_caps'}; {'id': '294', 'type': 'string', 'children': [], 'value': '"browserVersion"'}, {'id': '295', 'type': 'if_statement', 'children': ['296', '309']}; {'id': '296', 'type': 'comparison_operator', 'children': ['297', '304'], 'value': '!='}, {'id': '297', 'type': 'call', 'children': ['298', '303']}; {'id': '298', 'type': 'attribute', 'children': ['299', '302']}, {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'driver_caps'}, {'id': '301', 'type': 'string', 'children': [], 'value': '"platformName"'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '303', 'type': 'argument_list', 'children': []}; {'id': '304', 'type': 'attribute', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'platform'}, {'id': '309', 'type': 'block', 'children': ['310']}; {'id': '310', 'type': 'raise_statement', 'children': ['311']}, {'id': '311', 'type': 'call', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '313', 'type': 'argument_list', 'children': ['314']}; {'id': '314', 'type': 'concatenated_string', 'children': ['315', '316']}, {'id': '315', 'type': 'string', 'children': [], 'value': '"the platform you want is not the one "'}; {'id': '316', 'type': 'string', 'children': [], 'value': '"you are running selenic on"'}, {'id': '317', 'type': 'if_statement', 'children': ['318', '325']}; {'id': '318', 'type': 'comparison_operator', 'children': ['319', '320'], 'value': '!='}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'browser_version'}; {'id': '320', 'type': 'attribute', 'children': ['321', '324']}, {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '325', 'type': 'block', 'children': ['326']}; {'id': '326', 'type': 'raise_statement', 'children': ['327']}, {'id': '327', 'type': 'call', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '329', 'type': 'argument_list', 'children': ['330']}; {'id': '330', 'type': 'concatenated_string', 'children': ['331', '332']}, {'id': '331', 'type': 'string', 'children': [], 'value': '"the version installed is not the one "'}; {'id': '332', 'type': 'string', 'children': [], 'value': '"you wanted"'}, {'id': '333', 'type': 'if_statement', 'children': ['334', '359']}; {'id': '334', 'type': 'boolean_operator', 'children': ['335', '347', '348'], 'value': 'or'}, {'id': '335', 'type': 'parenthesized_expression', 'children': ['336'], 'value': '()'}; {'id': '336', 'type': 'boolean_operator', 'children': ['337', '340'], 'value': 'and'}, {'id': '337', 'type': 'attribute', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'remote_service'}; {'id': '340', 'type': 'comparison_operator', 'children': ['341', '346'], 'value': '=='}, {'id': '341', 'type': 'attribute', 'children': ['342', '345']}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'remote_service'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '346', 'type': 'string', 'children': [], 'value': '"browserstack"'}, {'id': '347', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '348', 'type': 'parenthesized_expression', 'children': ['349'], 'value': '()'}, {'id': '349', 'type': 'boolean_operator', 'children': ['350', '353'], 'value': 'and'}; {'id': '350', 'type': 'comparison_operator', 'children': ['351', '352'], 'value': 'is'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'chromedriver_version'}; {'id': '352', 'type': 'None', 'children': []}, {'id': '353', 'type': 'comparison_operator', 'children': ['354', '355'], 'value': '>'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'chromedriver_version'}, {'id': '355', 'type': 'call', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'StrictVersion'}, {'id': '357', 'type': 'argument_list', 'children': ['358']}; {'id': '358', 'type': 'string', 'children': [], 'value': '"2.13"'}, {'id': '359', 'type': 'block', 'children': ['360', '364']}; {'id': '360', 'type': 'expression_statement', 'children': ['361']}, {'id': '361', 'type': 'call', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'chromedriver_element_center_patch'}, {'id': '363', 'type': 'argument_list', 'children': []}; {'id': '364', 'type': 'expression_statement', 'children': ['365']}, {'id': '365', 'type': 'call', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '367', 'type': 'argument_list', 'children': ['368', '369', '370']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'driver'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'CHROMEDRIVER_ELEMENT_CENTER_PATCH_FLAG'}; {'id': '370', 'type': 'True', 'children': []}, {'id': '371', 'type': 'expression_statement', 'children': ['372']}; {'id': '372', 'type': 'assignment', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'driver'}; {'id': '374', 'type': 'call', 'children': ['375', '378']}, {'id': '375', 'type': 'attribute', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'patch'}; {'id': '378', 'type': 'argument_list', 'children': ['379']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'driver'}; {'id': '380', 'type': 'return_statement', 'children': ['381']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'driver'}
def get_driver(self, desired_capabilities=None): override_caps = desired_capabilities or {} desired_capabilities = \ self.config.make_selenium_desired_capabilities() desired_capabilities.update(override_caps) browser_string = self.config.browser chromedriver_version = None if self.remote: driver = self.remote_service.build_driver(desired_capabilities) if browser_string == "CHROME" and \ self.remote_service.name == "saucelabs": chromedriver_version = \ desired_capabilities.get("chromedriver-version", None) if chromedriver_version is None: raise ValueError( "when using Chrome, you must set a " "``chromedriver-version`` capability so that Selenic " "can detect which version of Chromedriver will " "be used.") else: if browser_string == "CHROME": chromedriver_path = self.local_conf["CHROMEDRIVER_PATH"] driver = webdriver.Chrome( chromedriver_path, chrome_options=self.local_conf.get("CHROME_OPTIONS"), desired_capabilities=desired_capabilities, service_log_path=self.local_conf["SERVICE_LOG_PATH"], service_args=self.local_conf.get("SERVICE_ARGS")) version_line = subprocess.check_output( [chromedriver_path, "--version"]) version_str = re.match(ur"^ChromeDriver (\d+\.\d+)", version_line).group(1) chromedriver_version = StrictVersion(version_str) elif browser_string == "FIREFOX": profile = self.local_conf.get("FIREFOX_PROFILE") or \ FirefoxProfile() binary = self.local_conf.get("FIREFOX_BINARY") or \ FirefoxBinary() driver = webdriver.Firefox(profile, binary, capabilities=desired_capabilities) elif browser_string == "INTERNETEXPLORER": driver = webdriver.Ie() elif browser_string == "OPERA": driver = webdriver.Opera() else: raise ValueError("can't start a local " + browser_string) driver_caps = NormalizedCapabilities(driver.desired_capabilities) browser_version = \ re.sub(r"\..*$", "", driver_caps["browserVersion"]) if driver_caps["platformName"].upper() != self.config.platform: raise ValueError("the platform you want is not the one " "you are running selenic on") if browser_version != self.config.version: raise ValueError("the version installed is not the one " "you wanted") if (self.remote_service and self.remote_service.name == "browserstack") or \ (chromedriver_version is not None and chromedriver_version > StrictVersion("2.13")): chromedriver_element_center_patch() setattr(driver, CHROMEDRIVER_ELEMENT_CENTER_PATCH_FLAG, True) driver = self.patch(driver) return driver
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'typedef'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'try_statement', 'children': ['11', '20', '33']}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'bound_type'}, {'id': '15', 'type': 'subscript', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'bound_types'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'typedef'}; {'id': '20', 'type': 'except_clause', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'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': 'DeclareException'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': '"Can\'t load unknown type {}"'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'typedef'}, {'id': '33', 'type': 'else_clause', 'children': ['34']}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'bound_type'}, {'id': '39', 'type': 'string', 'children': [], 'value': '"load"'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '42', 'type': 'dictionary_splat', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def load(self, typedef, value, **kwargs): try: bound_type = self.bound_types[typedef] except KeyError: raise DeclareException( "Can't load unknown type {}".format(typedef)) else: return bound_type["load"](value, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteSetLexer'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'lexer'}; {'id': '6', 'type': 'block', 'children': ['7', '31', '37', '60']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '22']}; {'id': '8', 'type': 'boolean_operator', 'children': ['9', '13'], 'value': 'and'}, {'id': '9', 'type': 'parenthesized_expression', 'children': ['10'], 'value': '()'}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'lexer'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'parenthesized_expression', 'children': ['14'], 'value': '()'}; {'id': '14', 'type': 'not_operator', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'issubclass'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'lexer'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Qsci'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'QsciLexer'}; {'id': '22', 'type': 'block', 'children': ['23', '30']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'QtmacsOtherError'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'concatenated_string', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'lexer must be a class object and derived from'"}, {'id': '29', 'type': 'string', 'children': [], 'value': "' <b>QsciLexer</b>'"}; {'id': '30', 'type': 'return_statement', 'children': []}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'qteLastLexer'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'lexer'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '41', '49']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'is'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'lexer'}; {'id': '40', 'type': 'None', 'children': []}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'setLexer'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'None', 'children': []}, {'id': '49', 'type': 'else_clause', 'children': ['50']}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'setLexer'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'lexer'}, {'id': '59', 'type': 'argument_list', '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': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'setMonospace'}, {'id': '65', 'type': 'argument_list', 'children': []}
def qteSetLexer(self, lexer): if (lexer is not None) and (not issubclass(lexer, Qsci.QsciLexer)): QtmacsOtherError('lexer must be a class object and derived from' ' <b>QsciLexer</b>') return self.qteLastLexer = lexer if lexer is None: self.setLexer(None) else: self.setLexer(lexer()) self.setMonospace()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_function_args'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'no_self'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'no_varargs'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '21', '34', '47', '54', '90', '114', '141', '163', '191']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'par_dict'}, {'id': '15', 'type': 'attribute', 'children': ['16', '20']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'signature'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '24', 'type': 'lambda', 'children': ['25', '27']}, {'id': '25', 'type': 'lambda_parameters', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': '=='}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'Parameter'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'VAR_POSITIONAL'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '37', 'type': 'lambda', 'children': ['38', '40']}; {'id': '38', 'type': 'lambda_parameters', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': '=='}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'Parameter'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'VAR_KEYWORD'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '50', 'type': 'list', 'children': ['51', '52', '53'], 'value': '["", "*", "**"]'}, {'id': '51', 'type': 'string', 'children': [], 'value': '""'}; {'id': '52', 'type': 'string', 'children': [], 'value': '"*"'}, {'id': '53', 'type': 'string', 'children': [], 'value': '"**"'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '57', 'type': 'list_comprehension', 'children': ['58', '81']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': '"{prefix}{arg}"'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '78']}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'opts'}, {'id': '67', 'type': 'binary_operator', 'children': ['68', '72'], 'value': '+'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '*'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'par'}, {'id': '81', 'type': 'for_in_clause', 'children': ['82', '85']}; {'id': '82', 'type': 'pattern_list', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'par'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'par_dict'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '89', 'type': 'argument_list', 'children': []}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self_filtered_args'}, {'id': '93', 'type': 'parenthesized_expression', 'children': ['94'], 'value': '()'}; {'id': '94', 'type': 'conditional_expression', 'children': ['95', '96', '98'], 'value': 'if'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '96', 'type': 'not_operator', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '98', 'type': 'parenthesized_expression', 'children': ['99'], 'value': '()'}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '101', 'type': 'slice', 'children': ['102', '113']}; {'id': '102', 'type': 'conditional_expression', 'children': ['103', '104', '112'], 'value': 'if'}, {'id': '103', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '104', 'type': 'boolean_operator', 'children': ['105', '111'], 'value': 'and'}, {'id': '105', 'type': 'parenthesized_expression', 'children': ['106'], 'value': '()'}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '110'], 'value': '=='}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '110', 'type': 'string', 'children': [], 'value': '"self"'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'no_self'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '113', 'type': 'colon', 'children': []}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '117', 'type': 'lambda', 'children': ['118', '120']}; {'id': '118', 'type': 'lambda_parameters', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '120', 'type': 'boolean_operator', 'children': ['121', '135'], 'value': 'and'}, {'id': '121', 'type': 'boolean_operator', 'children': ['122', '129'], 'value': 'and'}; {'id': '122', 'type': 'parenthesized_expression', 'children': ['123'], 'value': '()'}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '128'], 'value': '>'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '128', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '129', 'type': 'parenthesized_expression', 'children': ['130'], 'value': '()'}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '134'], 'value': '=='}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '134', 'type': 'string', 'children': [], 'value': '"*"'}, {'id': '135', 'type': 'parenthesized_expression', 'children': ['136'], 'value': '()'}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '140'], 'value': '!='}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '140', 'type': 'string', 'children': [], 'value': '"*"'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '144', 'type': 'lambda', 'children': ['145', '147']}, {'id': '145', 'type': 'lambda_parameters', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '147', 'type': 'boolean_operator', 'children': ['148', '155'], 'value': 'and'}; {'id': '148', 'type': 'parenthesized_expression', 'children': ['149'], 'value': '()'}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '154'], 'value': '>'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '155', 'type': 'parenthesized_expression', 'children': ['156'], 'value': '()'}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '162'], 'value': '=='}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '159', 'type': 'slice', 'children': ['160', '161']}; {'id': '160', 'type': 'colon', 'children': []}, {'id': '161', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '162', 'type': 'string', 'children': [], 'value': '"**"'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'varargs_filtered_args'}; {'id': '166', 'type': 'list_comprehension', 'children': ['167', '168', '171']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '168', 'type': 'for_in_clause', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'self_filtered_args'}, {'id': '171', 'type': 'if_clause', 'children': ['172']}; {'id': '172', 'type': 'boolean_operator', 'children': ['173', '176'], 'value': 'or'}, {'id': '173', 'type': 'parenthesized_expression', 'children': ['174'], 'value': '()'}; {'id': '174', 'type': 'not_operator', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'no_varargs'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'list', 'children': ['180', '181', '186'], 'value': '[no_varargs, not pos(arg), not kw(arg)]'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'no_varargs'}, {'id': '181', 'type': 'not_operator', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '186', 'type': 'not_operator', 'children': ['187']}, {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '191', 'type': 'return_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'varargs_filtered_args'}
def get_function_args(func, no_self=False, no_varargs=False): par_dict = signature(func).parameters pos = lambda x: x.kind == Parameter.VAR_POSITIONAL kw = lambda x: x.kind == Parameter.VAR_KEYWORD opts = ["", "*", "**"] args = [ "{prefix}{arg}".format(prefix=opts[pos(value) + 2 * kw(value)], arg=par) for par, value in par_dict.items() ] self_filtered_args = ( args if not args else (args[1 if (args[0] == "self") and no_self else 0 :]) ) pos = lambda x: (len(x) > 1) and (x[0] == "*") and (x[1] != "*") kw = lambda x: (len(x) > 2) and (x[:2] == "**") varargs_filtered_args = [ arg for arg in self_filtered_args if (not no_varargs) or all([no_varargs, not pos(arg), not kw(arg)]) ] return tuple(varargs_filtered_args)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_close_callable'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '22', '30', '31', '35', '81', '90', '95', '96', '100', '221', '227', '236', '252']}; {'id': '10', 'type': 'try_statement', 'children': ['11', '18']}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'lineno'}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'lineno'}; {'id': '18', 'type': 'except_clause', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'return_statement', 'children': []}; {'id': '22', 'type': 'if_statement', 'children': ['23', '28']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': '<='}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'lineno'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_processed_line'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': []}; {'id': '30', 'type': 'comment', 'children': []}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '34', 'type': 'string', 'children': [], 'value': '""'}, {'id': '35', 'type': 'try_statement', 'children': ['36', '77']}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '40', 'type': 'parenthesized_expression', 'children': ['41'], 'value': '()'}, {'id': '41', 'type': 'conditional_expression', 'children': ['42', '45', '50'], 'value': 'if'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '49', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '50', 'type': 'parenthesized_expression', 'children': ['51'], 'value': '()'}, {'id': '51', 'type': 'conditional_expression', 'children': ['52', '59', '68'], 'value': 'if'}; {'id': '52', 'type': 'attribute', 'children': ['53', '58']}, {'id': '53', 'type': 'subscript', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'targets'}, {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '67']}; {'id': '62', 'type': 'subscript', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '67', 'type': 'string', 'children': [], 'value': '"id"'}; {'id': '68', 'type': 'attribute', 'children': ['69', '76']}, {'id': '69', 'type': 'attribute', 'children': ['70', '75']}; {'id': '70', 'type': 'subscript', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '77', 'type': 'except_clause', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'pass_statement', 'children': []}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '_get_indent'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '93', 'type': 'unary_operator', 'children': ['94'], 'value': '-'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '95', 'type': 'comment', 'children': []}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'dlist'}, {'id': '99', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '100', 'type': 'while_statement', 'children': ['101', '110']}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '>='}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '103', 'type': 'unary_operator', 'children': ['104'], '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': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '_indent_stack'}; {'id': '110', 'type': 'block', 'children': ['111', '121', '133', '143', '153', '154', '211', '217']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'element_full_name'}; {'id': '114', 'type': 'subscript', 'children': ['115', '120']}, {'id': '115', 'type': 'subscript', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_indent_stack'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '120', 'type': 'string', 'children': [], 'value': '"full_name"'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'edict'}; {'id': '124', 'type': 'call', 'children': ['125', '130']}, {'id': '125', 'type': 'attribute', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': '_callables_db'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'element_full_name'}; {'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': 'stack_indent'}; {'id': '136', 'type': 'subscript', 'children': ['137', '142']}, {'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': '_indent_stack'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '142', 'type': 'string', 'children': [], 'value': '"level"'}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'open_callable'}; {'id': '146', 'type': 'boolean_operator', 'children': ['147', '148'], 'value': 'and'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'element_full_name'}; {'id': '148', 'type': 'parenthesized_expression', 'children': ['149'], 'value': '()'}, {'id': '149', 'type': 'not_operator', 'children': ['150']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'edict'}; {'id': '152', 'type': 'string', 'children': [], 'value': '"last_lineno"'}, {'id': '153', 'type': 'comment', 'children': []}; {'id': '154', 'type': 'if_statement', 'children': ['155', '194', '195']}, {'id': '155', 'type': 'boolean_operator', 'children': ['156', '157'], 'value': 'and'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'open_callable'}, {'id': '157', 'type': 'parenthesized_expression', 'children': ['158'], 'value': '()'}; {'id': '158', 'type': 'boolean_operator', 'children': ['159', '165'], 'value': 'or'}, {'id': '159', 'type': 'boolean_operator', 'children': ['160', '161'], 'value': 'or'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'force'}, {'id': '161', 'type': 'parenthesized_expression', 'children': ['162'], 'value': '()'}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '<'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'stack_indent'}, {'id': '165', 'type': 'parenthesized_expression', 'children': ['166'], 'value': '()'}; {'id': '166', 'type': 'boolean_operator', 'children': ['167', '171'], 'value': 'and'}, {'id': '167', 'type': 'parenthesized_expression', 'children': ['168'], 'value': '()'}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': '=='}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'stack_indent'}, {'id': '171', 'type': 'parenthesized_expression', 'children': ['172'], 'value': '()'}; {'id': '172', 'type': 'boolean_operator', 'children': ['173', '179'], 'value': 'or'}, {'id': '173', 'type': 'parenthesized_expression', 'children': ['174'], 'value': '()'}; {'id': '174', 'type': 'comparison_operator', 'children': ['175', '178'], 'value': '!='}, {'id': '175', 'type': 'subscript', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'edict'}, {'id': '177', 'type': 'string', 'children': [], 'value': '"type"'}; {'id': '178', 'type': 'string', 'children': [], 'value': '"prop"'}, {'id': '179', 'type': 'parenthesized_expression', 'children': ['180'], 'value': '()'}; {'id': '180', 'type': 'boolean_operator', 'children': ['181', '187'], 'value': 'and'}, {'id': '181', 'type': 'parenthesized_expression', 'children': ['182'], 'value': '()'}; {'id': '182', 'type': 'comparison_operator', 'children': ['183', '186'], 'value': '=='}, {'id': '183', 'type': 'subscript', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'edict'}, {'id': '185', 'type': 'string', 'children': [], 'value': '"type"'}; {'id': '186', 'type': 'string', 'children': [], 'value': '"prop"'}, {'id': '187', 'type': 'parenthesized_expression', 'children': ['188'], 'value': '()'}; {'id': '188', 'type': 'boolean_operator', 'children': ['189', '190'], 'value': 'and'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '190', 'type': 'parenthesized_expression', 'children': ['191'], 'value': '()'}, {'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': '!='}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'element_full_name'}; {'id': '194', 'type': 'comment', 'children': []}, {'id': '195', 'type': 'block', 'children': ['196', '204']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '201']}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'edict'}; {'id': '200', 'type': 'string', 'children': [], 'value': '"last_lineno"'}, {'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '-'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'lineno'}, {'id': '203', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'dlist'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '211', 'type': 'if_statement', 'children': ['212', '215']}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '214'], 'value': '>'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'stack_indent'}, {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'break_statement', 'children': []}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'augmented_assignment', 'children': ['219', '220'], 'value': '-='}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '220', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': '_indent_stack'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'stack_length'}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': '_indent_stack'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'dlist'}, {'id': '239', 'type': 'list_comprehension', 'children': ['240', '241', '244']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '241', 'type': 'for_in_clause', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'dlist'}; {'id': '244', 'type': 'if_clause', 'children': ['245']}, {'id': '245', 'type': 'comparison_operator', 'children': ['246', '251'], 'value': '!='}; {'id': '246', 'type': 'subscript', 'children': ['247', '250']}, {'id': '247', 'type': 'subscript', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '250', 'type': 'string', 'children': [], 'value': '"type"'}, {'id': '251', 'type': 'string', 'children': [], 'value': '"module"'}; {'id': '252', 'type': 'for_statement', 'children': ['253', '254', '255']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'dlist'}, {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'delete_statement', 'children': ['257']}, {'id': '257', 'type': 'subscript', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': '_indent_stack'}, {'id': '261', 'type': 'binary_operator', 'children': ['262', '263'], 'value': '+'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'stack_length'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'item'}
def _close_callable(self, node, force=False): try: lineno = node.lineno except AttributeError: return if lineno <= self._processed_line: return # code = name = "" try: name = ( node.name if hasattr(node, "name") else ( node.targets[0].id if hasattr(node.targets[0], "id") else node.targets[0].value.id ) ) except AttributeError: pass indent = self._get_indent(node) count = -1 # code = dlist = [] while count >= -len(self._indent_stack): element_full_name = self._indent_stack[count]["full_name"] edict = self._callables_db.get(element_full_name, None) stack_indent = self._indent_stack[count]["level"] open_callable = element_full_name and (not edict["last_lineno"]) # code = if open_callable and ( force or (indent < stack_indent) or ( (indent == stack_indent) and ( (edict["type"] != "prop") or ( (edict["type"] == "prop") and (name and (name != element_full_name)) ) ) ) ): # code = edict["last_lineno"] = lineno - 1 dlist.append(count) if indent > stack_indent: break count -= 1 stack = self._indent_stack stack_length = len(self._indent_stack) dlist = [item for item in dlist if stack[item]["type"] != "module"] for item in dlist: del self._indent_stack[stack_length + item]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteRemoveKey'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'keysequence'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'QtmacsKeysequence'}, {'id': '9', 'type': 'block', 'children': ['10', '14', '18', '26', '47', '68', '77']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'keyMap'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'keyMapRef'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'keyMap'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'keysequence'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'keysequence'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'toQtKeylist'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'for_statement', 'children': ['27', '28', '34']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'keysequence'}; {'id': '30', 'type': 'slice', 'children': ['31', '32']}, {'id': '31', 'type': 'colon', 'children': []}; {'id': '32', 'type': 'unary_operator', 'children': ['33'], 'value': '-'}, {'id': '33', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '34', 'type': 'block', 'children': ['35', '41']}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'not'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'keyMap'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'return_statement', 'children': []}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'keyMap'}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'keyMap'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '47', 'type': 'if_statement', 'children': ['48', '54', '56']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '53'], 'value': 'not'}, {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'keysequence'}, {'id': '51', 'type': 'unary_operator', 'children': ['52'], 'value': '-'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'keyMap'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'return_statement', 'children': []}; {'id': '56', 'type': 'else_clause', 'children': ['57']}, {'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': 'keyMap'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'keysequence'}; {'id': '66', 'type': 'unary_operator', 'children': ['67'], 'value': '-'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'keysequence'}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'keysequence'}, {'id': '73', 'type': 'slice', 'children': ['74', '75']}; {'id': '74', 'type': 'colon', 'children': []}, {'id': '75', 'type': 'unary_operator', 'children': ['76'], 'value': '-'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '77', 'type': 'while_statement', 'children': ['78', '83']}; {'id': '78', 'type': 'parenthesized_expression', 'children': ['79'], 'value': '()'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'keysequence'}, {'id': '83', 'type': 'block', 'children': ['84', '88', '103']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'keyMap'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'keyMapRef'}; {'id': '88', 'type': 'for_statement', 'children': ['89', '90', '96']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'keysequence'}; {'id': '92', 'type': 'slice', 'children': ['93', '94']}, {'id': '93', 'type': 'colon', 'children': []}; {'id': '94', 'type': 'unary_operator', 'children': ['95'], 'value': '-'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'keyMap'}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'keyMap'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '110', '112']}; {'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': 'keyMap'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'return_statement', 'children': []}; {'id': '112', 'type': 'else_clause', 'children': ['113']}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'keyMap'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}
def qteRemoveKey(self, keysequence: QtmacsKeysequence): keyMap = self keyMapRef = keyMap keysequence = keysequence.toQtKeylist() for key in keysequence[:-1]: if key not in keyMap: return keyMap = keyMap[key] if keysequence[-1] not in keyMap: return else: keyMap.pop(keysequence[-1]) keysequence = keysequence[:-1] while(len(keysequence)): keyMap = keyMapRef for key in keysequence[:-1]: keyMap = keyMap[key] if len(keyMap[key]): return else: keyMap.pop(key)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_labels'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'find_in_name'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'find_in_units'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '123', '160', '182']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '20']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '19'], 'value': 'is'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '20', 'type': 'block', 'children': ['21', '25', '121']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'found_keys'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '32', '84']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': "'~'"}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'for_statement', 'children': ['34', '37', '43']}; {'id': '34', 'type': 'pattern_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'label_no'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '43', 'type': 'block', 'children': ['44', '64']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '56']}, {'id': '45', 'type': 'boolean_operator', 'children': ['46', '47'], 'value': 'and'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'find_in_name'}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '53'], 'value': 'in'}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '50', 'type': 'slice', 'children': ['51', '52']}, {'id': '51', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '52', 'type': 'colon', 'children': []}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'found_keys'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'label_no'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '76']}, {'id': '65', 'type': 'boolean_operator', 'children': ['66', '67'], 'value': 'and'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'find_in_units'}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '73'], 'value': 'in'}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '70', 'type': 'slice', 'children': ['71', '72']}, {'id': '71', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '72', 'type': 'colon', 'children': []}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'found_keys'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'label_no'}; {'id': '84', 'type': 'else_clause', 'children': ['85']}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'for_statement', 'children': ['87', '90', '96']}, {'id': '87', 'type': 'pattern_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'label_no'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '96', 'type': 'block', 'children': ['97', '109']}, {'id': '97', 'type': 'if_statement', 'children': ['98', '105']}; {'id': '98', 'type': 'boolean_operator', 'children': ['99', '100'], 'value': 'and'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'find_in_name'}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '=='}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'return_statement', 'children': ['107']}, {'id': '107', 'type': 'list', 'children': ['108'], 'value': '[label_no]'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'label_no'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '117']}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '112'], 'value': 'and'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'find_in_units'}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '=='}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'units'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'return_statement', 'children': ['119']}, {'id': '119', 'type': 'list', 'children': ['120'], 'value': '[label_no]'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'label_no'}, {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'found_keys'}, {'id': '123', 'type': 'if_statement', 'children': ['124', '129']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'__call__'"}, {'id': '129', 'type': 'block', 'children': ['130', '134', '158']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'found_keys'}, {'id': '133', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '134', 'type': 'for_statement', 'children': ['135', '138', '144']}, {'id': '135', 'type': 'pattern_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'label_no'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'if_statement', 'children': ['146', '150']}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'found_keys'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'label_no'}; {'id': '158', 'type': 'return_statement', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'found_keys'}; {'id': '160', 'type': 'if_statement', 'children': ['161', '167']}, {'id': '161', 'type': 'comparison_operator', 'children': ['162', '166'], 'value': 'is'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'return_statement', 'children': ['169']}, {'id': '169', 'type': 'conditional_expression', 'children': ['170', '172', '181'], 'value': 'if'}; {'id': '170', 'type': 'list', 'children': ['171'], 'value': '[key]'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': '<'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '174', 'type': 'subscript', 'children': ['175', '180']}, {'id': '175', 'type': 'attribute', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'matrix'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '180', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '181', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '182', 'type': 'return_statement', 'children': ['183']}, {'id': '183', 'type': 'list', 'children': ['184'], 'value': '[key]'}
def find_labels(self,key,find_in_name=True,find_in_units=False): if type(key) is str: found_keys = [] if key.startswith('~'): for label_no,label in enumerate(self.labels): if find_in_name and key[1:] in label.name: found_keys.append(label_no) if find_in_units and key[1:] in label.units: found_keys.append(label_no) else: for label_no,label in enumerate(self.labels): if find_in_name and key == label.name: return [label_no] if find_in_units and key == label.units: return [label_no] return found_keys if hasattr(key, '__call__'): found_keys = [] for label_no,label in enumerate(self.labels): if key(label): found_keys.append(label_no) return found_keys if type(key) is int: return [key] if key < self.matrix.shape[1] else [] return [key]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_constrained_labels'}, {'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': 'remove_dimensions'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '15', '255']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'new_labels'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '15', 'type': 'for_statement', 'children': ['16', '19', '25']}; {'id': '16', 'type': 'pattern_list', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'label_no'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '25', 'type': 'block', 'children': ['26', '33', '37', '241', '248']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'new_label'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'LabelDimension'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '36', 'type': 'False', 'children': []}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '40', 'type': 'block', 'children': ['41', '68', '122', '148', '202', '228']}, {'id': '41', 'type': 'if_statement', 'children': ['42', '47']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '=='}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '47', 'type': 'block', 'children': ['48', '56', '64']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'new_label'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'new_label'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '67', 'type': 'True', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '76']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '=='}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '71', 'type': 'binary_operator', 'children': ['72', '75'], 'value': '+'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '75', 'type': 'string', 'children': [], 'value': "'__lt'"}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'if_statement', 'children': ['78', '83', '103']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': '=='}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'new_label'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'1'"}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'new_label'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'list', 'children': ['95', '98'], 'value': '[new_label.max,kwargs[k]-1]'}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'new_label'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '102'], 'value': '-'}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'k'}; {'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', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'new_label'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'list', 'children': ['116', '119'], 'value': '[new_label.max,kwargs[k]]'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'new_label'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '130']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '=='}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '125', 'type': 'binary_operator', 'children': ['126', '129'], 'value': '+'}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '129', 'type': 'string', 'children': [], 'value': "'__lte'"}; {'id': '130', 'type': 'block', 'children': ['131']}, {'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': 'new_label'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'list', 'children': ['142', '145'], 'value': '[new_label.max,kwargs[k]]'}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'new_label'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '156']}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '=='}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '151', 'type': 'binary_operator', 'children': ['152', '155'], 'value': '+'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '155', 'type': 'string', 'children': [], 'value': "'__gt'"}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'if_statement', 'children': ['158', '163', '183']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '162'], 'value': '=='}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'new_label'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'1'"}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'new_label'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'list', 'children': ['175', '178'], 'value': '[new_label.min,kwargs[k]+1]'}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'new_label'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '178', 'type': 'binary_operator', 'children': ['179', '182'], 'value': '+'}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '183', 'type': 'else_clause', 'children': ['184']}; {'id': '184', 'type': 'block', 'children': ['185']}, {'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': 'new_label'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'list', 'children': ['196', '199'], 'value': '[new_label.min,kwargs[k]]'}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'new_label'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '202', 'type': 'if_statement', 'children': ['203', '210']}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': '=='}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '205', 'type': 'binary_operator', 'children': ['206', '209'], 'value': '+'}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '209', 'type': 'string', 'children': [], 'value': "'__gte'"}; {'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': 'new_label'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '216', 'type': 'call', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'list', 'children': ['222', '225'], 'value': '[new_label.min,kwargs[k]]'}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'new_label'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '228', 'type': 'if_statement', 'children': ['229', '236']}, {'id': '229', 'type': 'comparison_operator', 'children': ['230', '231'], 'value': '=='}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '231', 'type': 'binary_operator', 'children': ['232', '235'], 'value': '+'}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '235', 'type': 'string', 'children': [], 'value': "'__evals'"}; {'id': '236', 'type': 'block', 'children': ['237']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '240', 'type': 'True', 'children': []}, {'id': '241', 'type': 'if_statement', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'remove_dimensions'}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'if_statement', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '246', 'type': 'block', 'children': ['247']}, {'id': '247', 'type': 'continue_statement', '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': 'new_labels'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'new_label'}, {'id': '255', 'type': 'return_statement', 'children': ['256']}
def _get_constrained_labels(self,remove_dimensions=False,**kwargs): new_labels = [] for label_no,label in enumerate(self.labels): new_label = LabelDimension(label) remove = False for k in kwargs: if k == label.name: new_label.max = kwargs[k] new_label.min = kwargs[k] remove = True if k == label.name+'__lt': if new_label.units == '1': new_label.max = np.min([new_label.max,kwargs[k]-1]) else: new_label.max = np.min([new_label.max,kwargs[k]]) if k == label.name+'__lte': new_label.max = np.min([new_label.max,kwargs[k]]) if k == label.name+'__gt': if new_label.units == '1': new_label.min = np.max([new_label.min,kwargs[k]+1]) else: new_label.min = np.max([new_label.min,kwargs[k]]) if k == label.name+'__gte': new_label.min = np.max([new_label.min,kwargs[k]]) if k == label.name+'__evals': remove = True if remove_dimensions: if remove: continue new_labels.append(new_label) return new_labels
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'populate_field_values'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'block', 'children': ['7', '36', '76', '222']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '14']}; {'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': '_meta'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'case_sensitive_fields'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '18', 'type': 'dictionary_comprehension', 'children': ['19', '26']}, {'id': '19', 'type': 'pair', 'children': ['20', '25']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '30']}, {'id': '27', 'type': 'pattern_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '42']}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'match_fuzzy_keys'}; {'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': 'data'}; {'id': '46', 'type': 'dictionary_comprehension', 'children': ['47', '66']}, {'id': '47', 'type': 'pair', 'children': ['48', '65']}; {'id': '48', 'type': 'call', 'children': ['49', '64']}, {'id': '49', 'type': 'attribute', 'children': ['50', '63']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': "''"}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '54', 'type': 'generator_expression', 'children': ['55', '56', '59']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '59', 'type': 'if_clause', 'children': ['60']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ALPHANUMERIC'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '66', 'type': 'for_in_clause', 'children': ['67', '70']}, {'id': '67', 'type': 'pattern_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '76', 'type': 'for_statement', 'children': ['77', '78', '83']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '83', 'type': 'block', 'children': ['84', '103', '107', '134', '213']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '87', 'type': 'conditional_expression', 'children': ['88', '91', '96'], 'value': 'if'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '91', 'type': 'attribute', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'case_sensitive_fields'}; {'id': '96', 'type': 'call', 'children': ['97', '102']}, {'id': '97', 'type': 'attribute', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '102', 'type': 'argument_list', 'children': []}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '106', 'type': 'None', 'children': []}, {'id': '107', 'type': 'if_statement', 'children': ['108', '113']}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'match_fuzzy_keys'}, {'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': 'name'}, {'id': '117', 'type': 'call', 'children': ['118', '133']}; {'id': '118', 'type': 'attribute', 'children': ['119', '132']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'string', 'children': [], 'value': "''"}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '123', 'type': 'generator_expression', 'children': ['124', '125', '128']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '125', 'type': 'for_in_clause', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '128', 'type': 'if_clause', 'children': ['129']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'in'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ALPHANUMERIC'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'if_statement', 'children': ['135', '138', '151', '195']}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'in'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'to_python'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '150']}, {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '151', 'type': 'elif_clause', 'children': ['152', '161']}; {'id': '152', 'type': 'boolean_operator', 'children': ['153', '156'], 'value': 'and'}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'required'}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '160'], 'value': 'is'}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '160', 'type': 'None', 'children': []}, {'id': '161', 'type': 'block', 'children': ['162', '176']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'string', 'children': [], 'value': '"Response from {0} is missing required field \'{1}\'"'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': '_url'}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '176', 'type': 'if_statement', 'children': ['177', '180', '186']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': '_strict'}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'raise_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'MissingFieldException'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'message'}; {'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': 'logger'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '195', 'type': 'elif_clause', 'children': ['196', '201']}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '200'], 'value': 'is'}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '200', 'type': 'None', 'children': []}, {'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': 'value'}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '218', '221']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': '_attr_name'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': '_populated_field_values'}, {'id': '227', 'type': 'True', 'children': []}
def populate_field_values(self, data): if not self._meta.case_sensitive_fields: data = {k.lower(): v for k, v in six.iteritems(data)} if self._meta.match_fuzzy_keys: data = {''.join(x for x in k if x in ALPHANUMERIC).lower(): v for k, v in six.iteritems(data)} for field in self._meta.fields: name = field.name if self._meta.case_sensitive_fields else field.name.lower() value = None if self._meta.match_fuzzy_keys: name = ''.join(x for x in name if x in ALPHANUMERIC).lower() if name in data: value = field.to_python(data[name], self) elif field.required and field.default is None: message = "Response from {0} is missing required field '{1}'".format(self._url, field.name) if self._strict: raise MissingFieldException(message) else: logger.warn(message) elif field.default is not None: value = copy.copy(field.default) setattr(self, field._attr_name, value) self._populated_field_values = True
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_contact'}, {'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': 'slug'}, {'id': '7', 'type': 'string', 'children': [], 'value': '""'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '29', '35', '41', '60', '132', '444']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_object_or_404'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ContactFormController'}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'slug'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'slug'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'site'}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Site'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_current'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'UserModel'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_user_model'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ContactForm'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '52', '57']}, {'id': '47', 'type': 'boolean_operator', 'children': ['48', '51'], 'value': 'or'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'POST'}, {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '56'], 'value': 'or'}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'FILES'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'}; {'id': '64', 'type': 'block', 'children': ['65', '82', '96', '106', '120']}, {'id': '65', 'type': 'try_statement', 'children': ['66', '73']}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'display_name'}, {'id': '73', 'type': 'except_clause', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'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': 'name'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '95']}; {'id': '84', 'type': 'subscript', 'children': ['85', '94']}, {'id': '85', 'type': 'attribute', 'children': ['86', '93']}; {'id': '86', 'type': 'attribute', 'children': ['87', '92']}, {'id': '87', 'type': 'subscript', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '91', 'type': 'string', 'children': [], 'value': "'sender_name'"}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'widget'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'readonly'"}, {'id': '95', 'type': 'string', 'children': [], 'value': "'true'"}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '105']}; {'id': '98', 'type': 'attribute', 'children': ['99', '104']}, {'id': '99', 'type': 'subscript', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'sender_name'"}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'initial'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '119']}; {'id': '108', 'type': 'subscript', 'children': ['109', '118']}, {'id': '109', 'type': 'attribute', 'children': ['110', '117']}; {'id': '110', 'type': 'attribute', 'children': ['111', '116']}, {'id': '111', 'type': 'subscript', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '115', 'type': 'string', 'children': [], 'value': "'sender_email'"}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'widget'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '118', 'type': 'string', 'children': [], 'value': "'readonly'"}, {'id': '119', 'type': 'string', 'children': [], 'value': "'true'"}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '129']}; {'id': '122', 'type': 'attribute', 'children': ['123', '128']}, {'id': '123', 'type': 'subscript', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '127', 'type': 'string', 'children': [], 'value': "'sender_email'"}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'initial'}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'email'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '138']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'is_valid'}, {'id': '137', 'type': 'argument_list', 'children': []}; {'id': '138', 'type': 'block', 'children': ['139', '185', '434']}, {'id': '139', 'type': 'if_statement', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'store_in_db'}, {'id': '143', 'type': 'block', 'children': ['144', '154', '160', '166', '179']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'new_msg'}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'Contact'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'dictionary_splat', 'children': ['151']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'form'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'new_msg'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'new_msg'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'site'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'site'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'override_subject'}; {'id': '170', 'type': 'block', 'children': ['171']}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'new_msg'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'override_subject'}, {'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': 'new_msg'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '184', 'type': 'argument_list', 'children': []}, {'id': '185', 'type': 'if_statement', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'send_emails'}, {'id': '189', 'type': 'block', 'children': ['190', '196', '234', '248', '273', '314', '356', '374', '396', '428']}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'form_data'}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'form'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}; {'id': '196', 'type': 'if_statement', 'children': ['197', '200', '207', '218']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'override_subject'}; {'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': 'subject'}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'override_subject'}, {'id': '207', 'type': 'elif_clause', 'children': ['208', '211']}; {'id': '208', 'type': 'comparison_operator', 'children': ['209', '210'], 'value': 'in'}, {'id': '209', 'type': 'string', 'children': [], 'value': "'subject'"}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'form_data'}, {'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': 'subject'}, {'id': '215', 'type': 'subscript', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'form_data'}, {'id': '217', 'type': 'string', 'children': [], 'value': "'subject'"}; {'id': '218', 'type': 'else_clause', 'children': ['219']}, {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'subject'}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'string', 'children': [], 'value': '"{} message from {}"'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '227', 'type': 'argument_list', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'form_data'}, {'id': '233', 'type': 'string', 'children': [], 'value': "'sender_name'"}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'string', 'children': [], 'value': '"{} \\n\\n {}"'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '245']}; {'id': '242', 'type': 'subscript', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'form_data'}; {'id': '244', 'type': 'string', 'children': [], 'value': "'body'"}, {'id': '245', 'type': 'subscript', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'form_data'}, {'id': '247', 'type': 'string', 'children': [], 'value': "'sender_name'"}; {'id': '248', 'type': 'if_statement', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'request_contact_info'}; {'id': '252', 'type': 'block', 'children': ['253']}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'augmented_assignment', 'children': ['255', '256'], 'value': '+='}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'string', 'children': [], 'value': '"\\nAddress: {} \\nCity: {} \\nState: {} \\nPhone: {}"'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '264', '267', '270']}, {'id': '261', 'type': 'subscript', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'form_data'}, {'id': '263', 'type': 'string', 'children': [], 'value': "'contact_address'"}; {'id': '264', 'type': 'subscript', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'form_data'}; {'id': '266', 'type': 'string', 'children': [], 'value': "'contact_city'"}, {'id': '267', 'type': 'subscript', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'form_data'}, {'id': '269', 'type': 'string', 'children': [], 'value': "'contact_state'"}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'form_data'}; {'id': '272', 'type': 'string', 'children': [], 'value': "'contact_phone'"}, {'id': '273', 'type': 'if_statement', 'children': ['274', '279']}; {'id': '274', 'type': 'comparison_operator', 'children': ['275', '278'], 'value': '=='}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'email_options'}; {'id': '278', 'type': 'string', 'children': [], 'value': "'2'"}, {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'try_statement', 'children': ['281', '302']}, {'id': '281', 'type': 'block', 'children': ['282']}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'assignment', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'to'}, {'id': '285', 'type': 'list', 'children': ['286'], 'value': "[UserModel.objects.get(username=form.cleaned_data['to']).email]"}; {'id': '286', 'type': 'attribute', 'children': ['287', '301']}, {'id': '287', 'type': 'call', 'children': ['288', '293']}; {'id': '288', 'type': 'attribute', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'UserModel'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'keyword_argument', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '296', 'type': 'subscript', 'children': ['297', '300']}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'form'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}; {'id': '300', 'type': 'string', 'children': [], 'value': "'to'"}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'email'}; {'id': '302', 'type': 'except_clause', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '304', 'type': 'block', 'children': ['305']}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '308', 'type': 'list', 'children': ['309'], 'value': "[form.cleaned_data['to']]"}, {'id': '309', 'type': 'subscript', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}, {'id': '313', 'type': 'string', 'children': [], 'value': "'to'"}; {'id': '314', 'type': 'if_statement', 'children': ['315', '320']}, {'id': '315', 'type': 'comparison_operator', 'children': ['316', '319'], 'value': '=='}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'email_options'}, {'id': '319', 'type': 'string', 'children': [], 'value': "'1'"}; {'id': '320', 'type': 'block', 'children': ['321', '337']}, {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'assignment', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '324', 'type': 'list_comprehension', 'children': ['325', '328']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'email'}; {'id': '328', 'type': 'for_in_clause', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '330', 'type': 'call', 'children': ['331', '336']}, {'id': '331', 'type': 'attribute', 'children': ['332', '335']}; {'id': '332', 'type': 'attribute', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'recipients'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '336', 'type': 'argument_list', 'children': []}, {'id': '337', 'type': 'for_statement', 'children': ['338', '339', '346']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '339', 'type': 'call', 'children': ['340', '345']}; {'id': '340', 'type': 'attribute', 'children': ['341', '344']}, {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'other_recipients'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '345', 'type': 'argument_list', 'children': []}; {'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': 'to'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '352', 'type': 'argument_list', 'children': ['353']}, {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'email'}; {'id': '356', 'type': 'if_statement', 'children': ['357', '362']}, {'id': '357', 'type': 'comparison_operator', 'children': ['358', '359'], 'value': 'in'}; {'id': '358', 'type': 'string', 'children': [], 'value': "'send_a_copy'"}, {'id': '359', 'type': 'attribute', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'form'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}; {'id': '362', 'type': 'block', 'children': ['363']}, {'id': '363', 'type': 'expression_statement', 'children': ['364']}; {'id': '364', 'type': 'call', 'children': ['365', '368']}, {'id': '365', 'type': 'attribute', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'to'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '368', 'type': 'argument_list', 'children': ['369']}, {'id': '369', 'type': 'subscript', 'children': ['370', '373']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}, {'id': '373', 'type': 'string', 'children': [], 'value': "'sender_email'"}; {'id': '374', 'type': 'expression_statement', 'children': ['375']}, {'id': '375', 'type': 'assignment', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'mail'}, {'id': '377', 'type': 'call', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'EmailMessage'}, {'id': '379', 'type': 'argument_list', 'children': ['380', '383', '386', '393']}; {'id': '380', 'type': 'keyword_argument', 'children': ['381', '382']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'subject'}, {'id': '383', 'type': 'keyword_argument', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '386', 'type': 'keyword_argument', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'from_email'}; {'id': '388', 'type': 'subscript', 'children': ['389', '392']}, {'id': '389', 'type': 'attribute', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'form'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'}; {'id': '392', 'type': 'string', 'children': [], 'value': "'sender_email'"}, {'id': '393', 'type': 'keyword_argument', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'to'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '396', 'type': 'if_statement', 'children': ['397', '402']}, {'id': '397', 'type': 'comparison_operator', 'children': ['398', '399'], 'value': 'in'}; {'id': '398', 'type': 'string', 'children': [], 'value': "'photo'"}, {'id': '399', 'type': 'attribute', 'children': ['400', '401']}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'FILES'}; {'id': '402', 'type': 'block', 'children': ['403', '411']}, {'id': '403', 'type': 'expression_statement', 'children': ['404']}; {'id': '404', 'type': 'assignment', 'children': ['405', '406']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'photo'}; {'id': '406', 'type': 'subscript', 'children': ['407', '410']}, {'id': '407', 'type': 'attribute', 'children': ['408', '409']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'FILES'}; {'id': '410', 'type': 'string', 'children': [], 'value': "'photo'"}, {'id': '411', 'type': 'expression_statement', 'children': ['412']}; {'id': '412', 'type': 'call', 'children': ['413', '416']}, {'id': '413', 'type': 'attribute', 'children': ['414', '415']}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'mail'}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'attach'}; {'id': '416', 'type': 'argument_list', 'children': ['417', '420', '425']}, {'id': '417', 'type': 'attribute', 'children': ['418', '419']}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'photo'}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '420', 'type': 'call', 'children': ['421', '424']}, {'id': '421', 'type': 'attribute', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'photo'}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '424', 'type': 'argument_list', 'children': []}, {'id': '425', 'type': 'attribute', 'children': ['426', '427']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'photo'}, {'id': '427', 'type': 'identifier', 'children': [], 'value': 'content_type'}; {'id': '428', 'type': 'expression_statement', 'children': ['429']}, {'id': '429', 'type': 'call', 'children': ['430', '433']}; {'id': '430', 'type': 'attribute', 'children': ['431', '432']}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'mail'}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'send'}, {'id': '433', 'type': 'argument_list', 'children': []}; {'id': '434', 'type': 'return_statement', 'children': ['435']}, {'id': '435', 'type': 'call', 'children': ['436', '437']}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'render'}, {'id': '437', 'type': 'argument_list', 'children': ['438', '439', '440']}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '439', 'type': 'string', 'children': [], 'value': "'success_url'"}; {'id': '440', 'type': 'dictionary', 'children': ['441']}, {'id': '441', 'type': 'pair', 'children': ['442', '443']}; {'id': '442', 'type': 'string', 'children': [], 'value': "'controller'"}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '444', 'type': 'return_statement', 'children': ['445']}, {'id': '445', 'type': 'call', 'children': ['446', '447']}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'render'}, {'id': '447', 'type': 'argument_list', 'children': ['448', '449', '450']}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '449', 'type': 'string', 'children': [], 'value': "'contact/form.html'"}; {'id': '450', 'type': 'dictionary', 'children': ['451', '454', '457']}, {'id': '451', 'type': 'pair', 'children': ['452', '453']}; {'id': '452', 'type': 'string', 'children': [], 'value': "'form'"}, {'id': '453', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '454', 'type': 'pair', 'children': ['455', '456']}, {'id': '455', 'type': 'string', 'children': [], 'value': "'site'"}; {'id': '456', 'type': 'identifier', 'children': [], 'value': 'site'}, {'id': '457', 'type': 'pair', 'children': ['458', '459']}; {'id': '458', 'type': 'string', 'children': [], 'value': "'controller'"}, {'id': '459', 'type': 'identifier', 'children': [], 'value': 'controller'}
def build_contact(request, slug=""): controller = get_object_or_404(ContactFormController, slug=slug) site = Site.objects.get_current() UserModel = get_user_model() user = request.user form = ContactForm(request.POST or None, request.FILES or None, controller=controller) if user.is_authenticated: try: name = user.display_name except AttributeError: name = user.username form.fields['sender_name'].widget.attrs['readonly'] = 'true' form.fields['sender_name'].initial = name form.fields['sender_email'].widget.attrs['readonly'] = 'true' form.fields['sender_email'].initial = user.email if form.is_valid(): if controller.store_in_db: new_msg = Contact(**form.cleaned_data) new_msg.controller = controller new_msg.site = site if controller.override_subject: new_msg.subject = controller.override_subject new_msg.save() if controller.send_emails: form_data = form.cleaned_data if controller.override_subject: subject = controller.override_subject elif 'subject' in form_data: subject = form_data['subject'] else: subject = "{} message from {}".format(controller.name, form_data['sender_name']) body = "{} \n\n {}".format(form_data['body'], form_data['sender_name']) if controller.request_contact_info: body += "\nAddress: {} \nCity: {} \nState: {} \nPhone: {}".format( form_data['contact_address'], form_data['contact_city'], form_data['contact_state'], form_data['contact_phone'] ) if controller.email_options == '2': try: to = [UserModel.objects.get(username=form.cleaned_data['to']).email] except Exception: to = [form.cleaned_data['to']] if controller.email_options == '1': to = [r.email for r in controller.recipients.all()] for r in controller.other_recipients.all(): to.append(r.email) if 'send_a_copy' in form.cleaned_data: to.append(form.cleaned_data['sender_email']) mail = EmailMessage( subject=subject, body=body, from_email=form.cleaned_data['sender_email'], to=to ) if 'photo' in request.FILES: photo = request.FILES['photo'] mail.attach(photo.name, photo.read(), photo.content_type) mail.send() return render(request, 'success_url', {'controller': controller}) return render(request, 'contact/form.html', { 'form': form, 'site': site, 'controller': controller })
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'stop_task'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'task_tag'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'stop_dependent'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'stop_requirements'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '24', '30', '66', '113', '210', '371', '381', '402']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'started_tasks'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'task_registry_id'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'task_tag'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'task'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': []}; {'id': '30', 'type': 'function_definition', 'children': ['31', '32', '34']}, {'id': '31', 'type': 'function_name', 'children': [], 'value': 'stop'}; {'id': '32', 'type': 'parameters', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'if_statement', 'children': ['36', '41']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'in'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '__started'}, {'id': '41', 'type': 'block', 'children': ['42', '57']}; {'id': '42', 'type': 'if_statement', 'children': ['43', '50']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '49'], 'value': 'is'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'WStoppableTask'}, {'id': '49', 'type': 'True', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '56', 'type': 'argument_list', 'children': []}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '64']}, {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '__started'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}; {'id': '66', 'type': 'function_definition', 'children': ['67', '68', '70']}, {'id': '67', 'type': 'function_name', 'children': [], 'value': 'stop_dependency'}; {'id': '68', 'type': 'parameters', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}; {'id': '70', 'type': 'block', 'children': ['71', '75', '99', '108']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'deeper_dependencies'}; {'id': '74', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '75', 'type': 'for_statement', 'children': ['76', '77', '80']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'dependent_task'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': '__started'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'if_statement', 'children': ['82', '91']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '86'], 'value': 'in'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': '__registry_tag__'}; {'id': '86', 'type': 'attribute', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'dependent_task'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '__dependency__'}, {'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': 'deeper_dependencies'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'dependent_task'}, {'id': '99', 'type': 'for_statement', 'children': ['100', '101', '102']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'dependent_task'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'deeper_dependencies'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'stop_dependency'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'dependent_task'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}, {'id': '113', 'type': 'function_definition', 'children': ['114', '115', '120']}; {'id': '114', 'type': 'function_name', 'children': [], 'value': 'calculate_requirements'}, {'id': '115', 'type': 'parameters', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}, {'id': '117', 'type': 'default_parameter', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'cross_requirements'}, {'id': '119', 'type': 'False', 'children': []}; {'id': '120', 'type': 'block', 'children': ['121', '127', '153', '160', '166', '208']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'requirements'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '126', 'type': 'argument_list', 'children': []}, {'id': '127', 'type': 'for_statement', 'children': ['128', '129', '132']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'dependent_task'}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': '__started'}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'if_statement', 'children': ['134', '145']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '140'], 'value': 'in'}, {'id': '135', 'type': 'attribute', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'dependent_task'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': '__registry_tag__'}; {'id': '140', 'type': 'attribute', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': '__dependency__'}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'requirements'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'dependent_task'}, {'id': '153', 'type': 'if_statement', 'children': ['154', '157']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'is'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'cross_requirements'}; {'id': '156', 'type': 'True', 'children': []}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'return_statement', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'requirements'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '165', 'type': 'argument_list', 'children': []}; {'id': '166', 'type': 'for_statement', 'children': ['167', '168', '169']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'task_a'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'requirements'}, {'id': '169', 'type': 'block', 'children': ['170', '174', '196']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'requirement_match'}, {'id': '173', 'type': 'False', 'children': []}; {'id': '174', 'type': 'for_statement', 'children': ['175', '176', '177']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'task_b'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'requirements'}, {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'if_statement', 'children': ['179', '190']}, {'id': '179', 'type': 'comparison_operator', 'children': ['180', '185'], 'value': 'in'}; {'id': '180', 'type': 'attribute', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'task_a'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': '__registry_tag__'}, {'id': '185', 'type': 'attribute', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'task_b'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': '__dependency__'}; {'id': '190', 'type': 'block', 'children': ['191', '195']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'requirement_match'}; {'id': '194', 'type': 'True', 'children': []}, {'id': '195', 'type': 'break_statement', 'children': []}; {'id': '196', 'type': 'if_statement', 'children': ['197', '200']}, {'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': 'is'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'requirement_match'}, {'id': '199', 'type': 'False', 'children': []}; {'id': '200', 'type': 'block', 'children': ['201']}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'task_a'}; {'id': '208', 'type': 'return_statement', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '210', 'type': 'function_definition', 'children': ['211', '212', '222']}, {'id': '211', 'type': 'function_name', 'children': [], 'value': 'calculate_priorities'}; {'id': '212', 'type': 'parameters', 'children': ['213', '214', '216', '219']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}; {'id': '214', 'type': 'list_splat_pattern', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'extra_tasks'}; {'id': '216', 'type': 'default_parameter', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'current_result'}; {'id': '218', 'type': 'None', 'children': []}, {'id': '219', 'type': 'default_parameter', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'requirements_left'}, {'id': '221', 'type': 'None', 'children': []}; {'id': '222', 'type': 'block', 'children': ['223', '232', '237', '252', '262', '274', '283', '316', '325', '346', '356']}, {'id': '223', 'type': 'if_statement', 'children': ['224', '227']}; {'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': 'is'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'current_result'}; {'id': '226', 'type': 'None', 'children': []}, {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'current_result'}, {'id': '231', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'tasks_to_stop'}, {'id': '235', 'type': 'list', 'children': ['236'], 'value': '[task_to_stop]'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'task_to_stop'}, {'id': '237', 'type': 'if_statement', 'children': ['238', '244']}; {'id': '238', 'type': 'comparison_operator', 'children': ['239', '243'], 'value': '>'}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'extra_tasks'}, {'id': '243', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'tasks_to_stop'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'extra_tasks'}; {'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': 'current_result'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'tasks_to_stop'}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'assignment', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'all_requirements'}, {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'calculate_requirements'}, {'id': '267', 'type': 'argument_list', 'children': ['268', '271']}; {'id': '268', 'type': 'subscript', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'tasks_to_stop'}; {'id': '270', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'cross_requirements'}, {'id': '273', 'type': 'True', 'children': []}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'assignment', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'nested_requirements'}, {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'calculate_requirements'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'tasks_to_stop'}; {'id': '282', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '283', 'type': 'for_statement', 'children': ['284', '285', '290']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'dependent_task'}, {'id': '285', 'type': 'subscript', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'tasks_to_stop'}, {'id': '287', 'type': 'slice', 'children': ['288', '289']}; {'id': '288', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '289', 'type': 'colon', 'children': []}; {'id': '290', 'type': 'block', 'children': ['291', '303']}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'assignment', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'nested_requirements'}; {'id': '294', 'type': 'call', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'nested_requirements'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}, {'id': '299', 'type': 'call', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'calculate_requirements'}, {'id': '301', 'type': 'argument_list', 'children': ['302']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'dependent_task'}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'call', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'all_requirements'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '308', 'type': 'argument_list', 'children': ['309']}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'calculate_requirements'}, {'id': '311', 'type': 'argument_list', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'dependent_task'}, {'id': '313', 'type': 'keyword_argument', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'cross_requirements'}, {'id': '315', 'type': 'True', 'children': []}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'assignment', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'all_requirements'}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'all_requirements'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'difference'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'nested_requirements'}, {'id': '325', 'type': 'if_statement', 'children': ['326', '329']}; {'id': '326', 'type': 'comparison_operator', 'children': ['327', '328'], 'value': 'is'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'requirements_left'}; {'id': '328', 'type': 'None', 'children': []}, {'id': '329', 'type': 'block', 'children': ['330', '339']}; {'id': '330', 'type': 'expression_statement', 'children': ['331']}, {'id': '331', 'type': 'assignment', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'requirements_left'}, {'id': '333', 'type': 'call', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'requirements_left'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'difference'}, {'id': '337', 'type': 'argument_list', 'children': ['338']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'all_requirements'}, {'id': '339', 'type': 'expression_statement', 'children': ['340']}; {'id': '340', 'type': 'call', 'children': ['341', '344']}, {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'nested_requirements'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '344', 'type': 'argument_list', 'children': ['345']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'requirements_left'}; {'id': '346', 'type': 'if_statement', 'children': ['347', '353']}, {'id': '347', 'type': 'comparison_operator', 'children': ['348', '352'], 'value': '=='}; {'id': '348', 'type': 'call', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '350', 'type': 'argument_list', 'children': ['351']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'nested_requirements'}; {'id': '352', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '353', 'type': 'block', 'children': ['354']}; {'id': '354', 'type': 'return_statement', 'children': ['355']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'current_result'}; {'id': '356', 'type': 'return_statement', 'children': ['357']}, {'id': '357', 'type': 'call', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'calculate_priorities'}, {'id': '359', 'type': 'argument_list', 'children': ['360', '365', '368']}; {'id': '360', 'type': 'list_splat', 'children': ['361']}, {'id': '361', 'type': 'call', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '363', 'type': 'argument_list', 'children': ['364']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'nested_requirements'}, {'id': '365', 'type': 'keyword_argument', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'current_result'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'current_result'}; {'id': '368', 'type': 'keyword_argument', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'requirements_left'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'all_requirements'}, {'id': '371', 'type': 'if_statement', 'children': ['372', '375']}; {'id': '372', 'type': 'comparison_operator', 'children': ['373', '374'], 'value': 'is'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'stop_dependent'}; {'id': '374', 'type': 'True', 'children': []}, {'id': '375', 'type': 'block', 'children': ['376']}; {'id': '376', 'type': 'expression_statement', 'children': ['377']}, {'id': '377', 'type': 'call', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'stop_dependency'}, {'id': '379', 'type': 'argument_list', 'children': ['380']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'task'}, {'id': '381', 'type': 'if_statement', 'children': ['382', '385']}; {'id': '382', 'type': 'comparison_operator', 'children': ['383', '384'], 'value': 'is'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'stop_requirements'}; {'id': '384', 'type': 'True', 'children': []}, {'id': '385', 'type': 'block', 'children': ['386']}; {'id': '386', 'type': 'for_statement', 'children': ['387', '388', '392']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'task_list'}; {'id': '388', 'type': 'call', 'children': ['389', '390']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'calculate_priorities'}; {'id': '390', 'type': 'argument_list', 'children': ['391']}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '392', 'type': 'block', 'children': ['393']}, {'id': '393', 'type': 'for_statement', 'children': ['394', '395', '396']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'single_task'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'task_list'}; {'id': '396', 'type': 'block', 'children': ['397']}, {'id': '397', 'type': 'expression_statement', 'children': ['398']}; {'id': '398', 'type': 'call', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '400', 'type': 'argument_list', 'children': ['401']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'single_task'}; {'id': '402', 'type': 'if_statement', 'children': ['403', '406']}, {'id': '403', 'type': 'comparison_operator', 'children': ['404', '405'], 'value': 'is'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'stop_dependent'}, {'id': '405', 'type': 'True', 'children': []}; {'id': '406', 'type': 'block', 'children': ['407']}, {'id': '407', 'type': 'expression_statement', 'children': ['408']}; {'id': '408', 'type': 'call', 'children': ['409', '410']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '410', 'type': 'argument_list', 'children': ['411']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'task'}
def stop_task(self, task_tag, stop_dependent=True, stop_requirements=False): task = self.started_tasks(task_registry_id=task_tag) if task is None: return def stop(task_to_stop): if task_to_stop in self.__started: if isinstance(task_to_stop, WStoppableTask) is True: task_to_stop.stop() self.__started.remove(task_to_stop) def stop_dependency(task_to_stop): deeper_dependencies = [] for dependent_task in self.__started: if task_to_stop.__registry_tag__ in dependent_task.__class__.__dependency__: deeper_dependencies.append(dependent_task) for dependent_task in deeper_dependencies: stop_dependency(dependent_task) stop(task_to_stop) def calculate_requirements(task_to_stop, cross_requirements=False): requirements = set() for dependent_task in self.__started: if dependent_task.__class__.__registry_tag__ in task_to_stop.__class__.__dependency__: requirements.add(dependent_task) if cross_requirements is True: return requirements result = set() for task_a in requirements: requirement_match = False for task_b in requirements: if task_a.__class__.__registry_tag__ in task_b.__class__.__dependency__: requirement_match = True break if requirement_match is False: result.add(task_a) return result def calculate_priorities(task_to_stop, *extra_tasks, current_result=None, requirements_left=None): if current_result is None: current_result = [] tasks_to_stop = [task_to_stop] if len(extra_tasks) > 0: tasks_to_stop.extend(extra_tasks) current_result.append(list(tasks_to_stop)) all_requirements = calculate_requirements(tasks_to_stop[0], cross_requirements=True) nested_requirements = calculate_requirements(tasks_to_stop[0]) for dependent_task in tasks_to_stop[1:]: nested_requirements = nested_requirements.union(calculate_requirements(dependent_task)) all_requirements.update(calculate_requirements(dependent_task, cross_requirements=True)) all_requirements = all_requirements.difference(nested_requirements) if requirements_left is not None: requirements_left = requirements_left.difference(all_requirements) nested_requirements.update(requirements_left) if len(nested_requirements) == 0: return current_result return calculate_priorities( *list(nested_requirements), current_result=current_result, requirements_left=all_requirements ) if stop_dependent is True: stop_dependency(task) if stop_requirements is True: for task_list in calculate_priorities(task): for single_task in task_list: stop(single_task) if stop_dependent is not True: stop(task)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'diffs2persistence'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'rev_docs'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'window_size'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '50'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'revert_radius'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '15'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sunset'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '29', '36', '43', '63', '80']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'rev_docs'}, {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'mwxml'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'utilities'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'normalize'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'rev_docs'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'window_size'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'window_size'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'revert_radius'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'revert_radius'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sunset'}; {'id': '46', 'type': 'conditional_expression', 'children': ['47', '51', '54', '55'], 'value': 'if'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Timestamp'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sunset'}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sunset'}, {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'Timestamp'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'page_docs'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'rev_docs'}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '72', 'type': 'lambda', 'children': ['73', '75']}, {'id': '73', 'type': 'lambda_parameters', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '75', 'type': 'subscript', 'children': ['76', '79']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'page'"}, {'id': '79', 'type': 'string', 'children': [], 'value': "'title'"}; {'id': '80', 'type': 'for_statement', 'children': ['81', '84', '85']}, {'id': '81', 'type': 'pattern_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'page_title'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'rev_docs'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'page_docs'}, {'id': '85', 'type': 'block', 'children': ['86', '100', '107', '116', '125', '300', '357']}; {'id': '86', 'type': 'if_statement', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '88', 'type': 'block', 'children': ['89']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '96']}, {'id': '91', 'type': 'attribute', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '+'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'page_title'}, {'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': 'rev_docs'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'peekable'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'rev_docs'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'deque'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'maxlen'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'window_size'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'DiffState'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'revert_radius'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'revert_radius'}, {'id': '125', 'type': 'while_statement', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'rev_docs'}, {'id': '127', 'type': 'block', 'children': ['128', '135', '144', '179', '200', '225']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'rev_doc'}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'rev_docs'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'next_doc'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'rev_docs'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'peek'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'None', 'children': []}; {'id': '144', 'type': 'if_statement', 'children': ['145', '148', '166']}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'is'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'next_doc'}, {'id': '147', 'type': 'None', 'children': []}; {'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': 'seconds_visible'}; {'id': '152', 'type': 'binary_operator', 'children': ['153', '159', '160'], 'value': '-'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'Timestamp'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'next_doc'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'timestamp'"}, {'id': '159', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'Timestamp'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'rev_doc'}, {'id': '165', 'type': 'string', 'children': [], 'value': "'timestamp'"}; {'id': '166', 'type': 'else_clause', 'children': ['167']}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'seconds_visible'}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '-'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'sunset'}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'Timestamp'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'rev_doc'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'timestamp'"}, {'id': '179', 'type': 'if_statement', 'children': ['180', '183']}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '<'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'seconds_visible'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '183', 'type': 'block', 'children': ['184', '196']}; {'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': 'logger'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'string', 'children': [], 'value': '"Seconds visible {0} is less than zero."'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'seconds_visible'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'seconds_visible'}, {'id': '199', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'assignment', 'children': ['202', '206', '207']}; {'id': '202', 'type': 'pattern_list', 'children': ['203', '204', '205']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'tokens_added'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '206', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'update_opdocs'}, {'id': '211', 'type': 'argument_list', 'children': ['212', '215', '220']}; {'id': '212', 'type': 'subscript', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'rev_doc'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'sha1'"}, {'id': '215', 'type': 'subscript', 'children': ['216', '219']}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'rev_doc'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'diff'"}, {'id': '219', 'type': 'string', 'children': [], 'value': "'ops'"}; {'id': '220', 'type': 'tuple', 'children': ['221', '224']}, {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'rev_doc'}, {'id': '223', 'type': 'string', 'children': [], 'value': "'user'"}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'seconds_visible'}, {'id': '225', 'type': 'if_statement', 'children': ['226', '232', '289']}; {'id': '226', 'type': 'comparison_operator', 'children': ['227', '231'], 'value': '=='}, {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'window'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'window_size'}; {'id': '232', 'type': 'block', 'children': ['233', '241', '250', '260', '266', '269']}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '238']}, {'id': '235', 'type': 'pattern_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'old_doc'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'old_added'}; {'id': '238', 'type': 'subscript', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '240', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'window'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'tuple', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'rev_doc'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'tokens_added'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'persistence'}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'token_persistence'}, {'id': '255', 'type': 'argument_list', 'children': ['256', '257', '258', '259']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'old_doc'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'old_added'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'window'}, {'id': '259', 'type': 'None', 'children': []}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '265']}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'old_doc'}; {'id': '264', 'type': 'string', 'children': [], 'value': "'persistence'"}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'persistence'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'yield', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'old_doc'}, {'id': '269', 'type': 'if_statement', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '271', 'type': 'block', 'children': ['272', '281']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'call', 'children': ['274', '279']}; {'id': '274', 'type': 'attribute', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '288']}, {'id': '283', 'type': 'attribute', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'flush'}; {'id': '288', 'type': 'argument_list', 'children': []}, {'id': '289', 'type': 'else_clause', 'children': ['290']}; {'id': '290', 'type': 'block', 'children': ['291']}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'window'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '296', 'type': 'argument_list', 'children': ['297']}, {'id': '297', 'type': 'tuple', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'rev_doc'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'tokens_added'}; {'id': '300', 'type': 'while_statement', 'children': ['301', '307']}, {'id': '301', 'type': 'comparison_operator', 'children': ['302', '306'], 'value': '>'}; {'id': '302', 'type': 'call', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '304', 'type': 'argument_list', 'children': ['305']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '306', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '307', 'type': 'block', 'children': ['308', '318', '328', '334', '337']}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'assignment', 'children': ['310', '313']}; {'id': '310', 'type': 'pattern_list', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'old_doc'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'old_added'}, {'id': '313', 'type': 'call', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'popleft'}, {'id': '317', 'type': 'argument_list', 'children': []}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'assignment', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'persistence'}, {'id': '321', 'type': 'call', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'token_persistence'}, {'id': '323', 'type': 'argument_list', 'children': ['324', '325', '326', '327']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'old_doc'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'old_added'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'window'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'sunset'}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'assignment', 'children': ['330', '333']}; {'id': '330', 'type': 'subscript', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'old_doc'}; {'id': '332', 'type': 'string', 'children': [], 'value': "'persistence'"}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'persistence'}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}, {'id': '335', 'type': 'yield', 'children': ['336']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'old_doc'}, {'id': '337', 'type': 'if_statement', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '339', 'type': 'block', 'children': ['340', '349']}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}, {'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': 'sys'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '347', 'type': 'argument_list', 'children': ['348']}; {'id': '348', 'type': 'string', 'children': [], 'value': '"_"'}, {'id': '349', 'type': 'expression_statement', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '356']}, {'id': '351', 'type': 'attribute', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'flush'}; {'id': '356', 'type': 'argument_list', 'children': []}, {'id': '357', 'type': 'if_statement', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '359', 'type': 'block', 'children': ['360']}; {'id': '360', 'type': 'expression_statement', 'children': ['361']}, {'id': '361', 'type': 'call', 'children': ['362', '367']}; {'id': '362', 'type': 'attribute', 'children': ['363', '366']}, {'id': '363', 'type': 'attribute', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '367', 'type': 'argument_list', 'children': ['368']}
def diffs2persistence(rev_docs, window_size=50, revert_radius=15, sunset=None, verbose=False): rev_docs = mwxml.utilities.normalize(rev_docs) window_size = int(window_size) revert_radius = int(revert_radius) sunset = Timestamp(sunset) if sunset is not None \ else Timestamp(time.time()) page_docs = groupby(rev_docs, key=lambda d: d['page']['title']) for page_title, rev_docs in page_docs: if verbose: sys.stderr.write(page_title + ": ") rev_docs = peekable(rev_docs) window = deque(maxlen=window_size) state = DiffState(revert_radius=revert_radius) while rev_docs: rev_doc = next(rev_docs) next_doc = rev_docs.peek(None) if next_doc is not None: seconds_visible = Timestamp(next_doc['timestamp']) - \ Timestamp(rev_doc['timestamp']) else: seconds_visible = sunset - Timestamp(rev_doc['timestamp']) if seconds_visible < 0: logger.warn("Seconds visible {0} is less than zero." .format(seconds_visible)) seconds_visible = 0 _, tokens_added, _ = \ state.update_opdocs(rev_doc['sha1'], rev_doc['diff']['ops'], (rev_doc['user'], seconds_visible)) if len(window) == window_size: old_doc, old_added = window[0] window.append((rev_doc, tokens_added)) persistence = token_persistence(old_doc, old_added, window, None) old_doc['persistence'] = persistence yield old_doc if verbose: sys.stderr.write(".") sys.stderr.flush() else: window.append((rev_doc, tokens_added)) while len(window) > 0: old_doc, old_added = window.popleft() persistence = token_persistence(old_doc, old_added, window, sunset) old_doc['persistence'] = persistence yield old_doc if verbose: sys.stderr.write("_") sys.stderr.flush() if verbose: sys.stderr.write("\n")
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteAddWidget'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '11', '16', '21']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'QWidget'}, {'id': '11', 'type': 'typed_default_parameter', 'children': ['12', '13', '15']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'isFocusable'}, {'id': '13', 'type': 'type', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '15', 'type': 'True', 'children': []}; {'id': '16', 'type': 'typed_default_parameter', 'children': ['17', '18', '20']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'widgetSignature'}; {'id': '18', 'type': 'type', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'typed_default_parameter', 'children': ['22', '23', '25']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'autoBind'}, {'id': '23', 'type': 'type', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '25', 'type': 'True', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '39', '51', '59', '71', '98', '102', '112', '122', '124', '135', '141', '267']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'QtmacsAdminStructure'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'isFocusable'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'isFocusable'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '46']}, {'id': '41', 'type': 'attribute', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'appletID'}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'appletID'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '58']}, {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'isQtmacsApplet'}; {'id': '58', 'type': 'False', 'children': []}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '66']}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'appletSignature'}; {'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': 'qteAppletSignature'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'if_statement', 'children': ['72', '75', '88']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'widgetSignature'}; {'id': '74', 'type': 'None', 'children': []}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '83']}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'widgetSignature'}, {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'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', '97']}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'widgetSignature'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'widgetSignature'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'wo'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'wo'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'qteSignature'}, {'id': '107', 'type': 'attribute', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'wo'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'widgetSignature'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'wo'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'qteSetKeyFilterPolicy'}, {'id': '117', 'type': 'attribute', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'wo'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'qteSetKeyFilterPolicy'}; {'id': '122', 'type': 'delete_statement', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'wo'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '133']}; {'id': '126', 'type': 'attribute', 'children': ['127', '132']}, {'id': '127', 'type': 'attribute', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'widgetList'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'default_bind'}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'qte_global'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'default_widget_keybindings'}, {'id': '141', 'type': 'if_statement', 'children': ['142', '150']}; {'id': '142', 'type': 'boolean_operator', 'children': ['143', '144'], 'value': 'and'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'autoBind'}; {'id': '144', 'type': 'parenthesized_expression', 'children': ['145'], 'value': '()'}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '149'], 'value': 'in'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'qteSignature'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'default_bind'}; {'id': '150', 'type': 'block', 'children': ['151', '159', '196']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'default_bind'}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'qteSignature'}, {'id': '159', 'type': 'try_statement', 'children': ['160', '170']}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'importlib'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'import_module'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '170', 'type': 'except_clause', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ImportError'}; {'id': '172', 'type': 'block', 'children': ['173', '183', '195']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '176', 'type': 'parenthesized_expression', 'children': ['177'], 'value': '()'}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'string', 'children': [], 'value': "'Module <b>{}</b> could not be imported.'"}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'module_name'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '190']}, {'id': '185', 'type': 'attribute', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'stack_info'}; {'id': '194', 'type': 'True', 'children': []}, {'id': '195', 'type': 'return_statement', 'children': []}; {'id': '196', 'type': 'if_statement', 'children': ['197', '202', '243']}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '199', 'type': 'argument_list', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '201', 'type': 'string', 'children': [], 'value': "'install_macros_and_bindings'"}; {'id': '202', 'type': 'block', 'children': ['203']}, {'id': '203', 'type': 'try_statement', 'children': ['204', '212']}; {'id': '204', 'type': 'block', 'children': ['205']}, {'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': 'mod'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'install_macros_and_bindings'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}; {'id': '212', 'type': 'except_clause', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '214', 'type': 'block', 'children': ['215', '222', '231']}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '218', 'type': 'parenthesized_expression', 'children': ['219'], 'value': '()'}, {'id': '219', 'type': 'concatenated_string', 'children': ['220', '221']}; {'id': '220', 'type': 'string', 'children': [], 'value': "'<b>install_macros_and_bindings</b> function'"}, {'id': '221', 'type': 'string', 'children': [], 'value': "' in <b>{}</b> did not execute properly.'"}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'module_name'}, {'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': 'self'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '238', 'type': 'argument_list', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'stack_info'}; {'id': '242', 'type': 'True', 'children': []}, {'id': '243', 'type': 'else_clause', 'children': ['244']}; {'id': '244', 'type': 'block', 'children': ['245', '258']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '248', 'type': 'parenthesized_expression', 'children': ['249'], 'value': '()'}, {'id': '249', 'type': 'call', 'children': ['250', '256']}; {'id': '250', 'type': 'attribute', 'children': ['251', '255']}, {'id': '251', 'type': 'concatenated_string', 'children': ['252', '253', '254']}; {'id': '252', 'type': 'string', 'children': [], 'value': "'Module <b>{}</b> has no '"}, {'id': '253', 'type': 'string', 'children': [], 'value': "'<b>install_macros_and_bindings</b>'"}; {'id': '254', 'type': 'string', 'children': [], 'value': "' method'"}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'call', 'children': ['260', '265']}; {'id': '260', 'type': 'attribute', 'children': ['261', '264']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '267', 'type': 'return_statement', 'children': ['268']}
def qteAddWidget(self, widgetObj: QtGui.QWidget, isFocusable: bool=True, widgetSignature: str=None, autoBind: bool=True): widgetObj._qteAdmin = QtmacsAdminStructure( self, isFocusable=isFocusable) widgetObj._qteAdmin.appletID = self._qteAdmin.appletID widgetObj._qteAdmin.isQtmacsApplet = False widgetObj._qteAdmin.appletSignature = self.qteAppletSignature() if widgetSignature is None: widgetObj._qteAdmin.widgetSignature = widgetObj.__class__.__name__ else: widgetObj._qteAdmin.widgetSignature = widgetSignature wo = widgetObj wo.qteSignature = wo._qteAdmin.widgetSignature wo.qteSetKeyFilterPolicy = wo._qteAdmin.qteSetKeyFilterPolicy del wo self._qteAdmin.widgetList.append(widgetObj) default_bind = qte_global.default_widget_keybindings if autoBind and (widgetObj.qteSignature in default_bind): module_name = default_bind[widgetObj.qteSignature] try: mod = importlib.import_module(module_name) except ImportError: msg = ('Module <b>{}</b> could not be imported.'.format( module_name)) self.qteLogger.exception(msg, stack_info=True) return if hasattr(mod, 'install_macros_and_bindings'): try: mod.install_macros_and_bindings(widgetObj) except Exception: msg = ('<b>install_macros_and_bindings</b> function' ' in <b>{}</b> did not execute properly.') msg = msg.format(module_name) self.qteLogger.error(msg, stack_info=True) else: msg = ('Module <b>{}</b> has no ' '<b>install_macros_and_bindings</b>' ' method'.format(module_name)) self.qteLogger.error(msg) return widgetObj
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteSetWidgetFocusOrder'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'widList'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '9', 'type': 'block', 'children': ['10', '19', '25', '37', '68', '75', '95', '104', '123', '140']}; {'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': 'widList'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': []}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'qteAutoremoveDeletedWidgets'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'widList'}; {'id': '28', 'type': 'list_comprehension', 'children': ['29', '30', '33']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'widList'}, {'id': '33', 'type': 'if_clause', 'children': ['34']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'widList'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'if_statement', 'children': ['42', '49']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'not'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'wid'}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'widgetList'}, {'id': '49', 'type': 'block', 'children': ['50', '54', '58', '67']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'Cannot change focus order because some '"}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'augmented_assignment', 'children': ['56', '57'], 'value': '+='}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '57', 'type': 'string', 'children': [], 'value': "'widgets do not exist.'"}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '65']}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '67', 'type': 'return_statement', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'newList'}, {'id': '71', 'type': 'list', 'children': ['72'], 'value': '[widList[0]]'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'widList'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '75', 'type': 'for_statement', 'children': ['76', '77', '82']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'widList'}, {'id': '79', 'type': 'slice', 'children': ['80', '81']}; {'id': '80', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '81', 'type': 'colon', 'children': []}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'if_statement', 'children': ['84', '87']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'not'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'wid'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'newList'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'newList'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '102']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '101'], 'value': '<'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'newList'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'return_statement', 'children': []}; {'id': '104', 'type': 'for_statement', 'children': ['105', '106', '111']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'wid'}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'newList'}; {'id': '108', 'type': 'slice', 'children': ['109', '110']}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'colon', 'children': []}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '121']}; {'id': '114', 'type': 'attribute', 'children': ['115', '120']}, {'id': '115', 'type': 'attribute', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'widgetList'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'startIdx'}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '139'], 'value': '+'}, {'id': '127', 'type': 'call', 'children': ['128', '135']}; {'id': '128', 'type': 'attribute', 'children': ['129', '134']}, {'id': '129', 'type': 'attribute', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'widgetList'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'newList'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '140', 'type': 'for_statement', 'children': ['141', '144', '152']}, {'id': '141', 'type': 'pattern_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'wid'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'newList'}, {'id': '149', 'type': 'slice', 'children': ['150', '151']}; {'id': '150', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '151', 'type': 'colon', 'children': []}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '162']}, {'id': '155', 'type': 'attribute', 'children': ['156', '161']}; {'id': '156', 'type': 'attribute', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'widgetList'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '166']}, {'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '+'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'startIdx'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'idx'}
def qteSetWidgetFocusOrder(self, widList: tuple): if len(widList) < 2: return self.qteAutoremoveDeletedWidgets() widList = [_ for _ in widList if _ is not None] for wid in widList: if wid not in self._qteAdmin.widgetList: msg = 'Cannot change focus order because some ' msg += 'widgets do not exist.' self.qteLogger.warning(msg) return newList = [widList[0]] for wid in widList[1:]: if wid not in newList: newList.append(wid) if len(newList) < 2: return for wid in newList[1:]: self._qteAdmin.widgetList.remove(wid) startIdx = self._qteAdmin.widgetList.index(newList[0]) + 1 for idx, wid in enumerate(newList[1:]): self._qteAdmin.widgetList.insert(startIdx + idx, wid)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '37']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteNextWidget'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '17', '22', '27', '32']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_default_parameter', 'children': ['6', '7', '9']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'numSkip'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '10', 'type': 'typed_default_parameter', 'children': ['11', '12', '16']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ofsWidget'}; {'id': '12', 'type': 'type', 'children': ['13']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'QtGui'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'QWidget'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'typed_default_parameter', 'children': ['18', '19', '21']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'skipVisible'}, {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '21', 'type': 'False', 'children': []}; {'id': '22', 'type': 'typed_default_parameter', 'children': ['23', '24', '26']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'skipInvisible'}; {'id': '24', 'type': 'type', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '26', 'type': 'True', 'children': []}, {'id': '27', 'type': 'typed_default_parameter', 'children': ['28', '29', '31']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'skipFocusable'}, {'id': '29', 'type': 'type', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '31', 'type': 'False', 'children': []}; {'id': '32', 'type': 'typed_default_parameter', 'children': ['33', '34', '36']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'skipUnfocusable'}; {'id': '34', 'type': 'type', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '36', 'type': 'True', 'children': []}, {'id': '37', 'type': 'block', 'children': ['38', '64', '70', '81', '106', '123', '141', '159', '176', '185', '196', '215', '233', '245']}; {'id': '38', 'type': 'if_statement', 'children': ['39', '50']}, {'id': '39', 'type': 'boolean_operator', 'children': ['40', '46'], 'value': 'and'}; {'id': '40', 'type': 'not_operator', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ofsWidget'}, {'id': '45', 'type': 'string', 'children': [], 'value': "'_qteAdmin'"}; {'id': '46', 'type': 'parenthesized_expression', 'children': ['47'], 'value': '()'}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ofsWidget'}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51', '55', '59']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'<ofsWidget> was probably not added with <qteAddWidget>'"}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'augmented_assignment', 'children': ['57', '58'], 'value': '+='}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '58', 'type': 'string', 'children': [], 'value': "' method because it lacks the <_qteAdmin> attribute.'"}, {'id': '59', 'type': 'raise_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'QtmacsOtherError'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'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': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'qteAutoremoveDeletedWidgets'}, {'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': 'widList'}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'widgetList'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '87']}; {'id': '82', 'type': 'not_operator', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'widList'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'if_statement', 'children': ['89', '97', '102']}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '96'], 'value': 'is'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'qteGetAppletFromWidget'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': '_qteActiveWidget'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'return_statement', 'children': ['99']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': '_qteActiveWidget'}; {'id': '102', 'type': 'else_clause', 'children': ['103']}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'return_statement', 'children': ['105']}, {'id': '105', 'type': 'None', 'children': []}; {'id': '106', 'type': 'if_statement', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'skipInvisible'}; {'id': '108', 'type': 'block', 'children': ['109']}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'widList'}; {'id': '112', 'type': 'list_comprehension', 'children': ['113', '114', '117']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'wid'}; {'id': '114', 'type': 'for_in_clause', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'wid'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'widList'}, {'id': '117', 'type': 'if_clause', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'isVisible'}; {'id': '122', 'type': 'argument_list', 'children': []}, {'id': '123', 'type': 'if_statement', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'skipVisible'}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'widList'}, {'id': '129', 'type': 'list_comprehension', 'children': ['130', '131', '134']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '131', 'type': 'for_in_clause', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'widList'}; {'id': '134', 'type': 'if_clause', 'children': ['135']}, {'id': '135', 'type': 'not_operator', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'isVisible'}; {'id': '140', 'type': 'argument_list', 'children': []}, {'id': '141', 'type': 'if_statement', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'skipFocusable'}, {'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': 'widList'}, {'id': '147', 'type': 'list_comprehension', 'children': ['148', '149', '152']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '149', 'type': 'for_in_clause', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'widList'}; {'id': '152', 'type': 'if_clause', 'children': ['153']}, {'id': '153', 'type': 'not_operator', 'children': ['154']}; {'id': '154', 'type': 'attribute', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'isFocusable'}, {'id': '159', 'type': 'if_statement', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'skipUnfocusable'}, {'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': 'widList'}, {'id': '165', 'type': 'list_comprehension', 'children': ['166', '167', '170']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '167', 'type': 'for_in_clause', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'wid'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'widList'}; {'id': '170', 'type': 'if_clause', 'children': ['171']}, {'id': '171', 'type': 'attribute', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'wid'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'isFocusable'}; {'id': '176', 'type': 'if_statement', 'children': ['177', '182']}, {'id': '177', 'type': 'not_operator', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'widList'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'return_statement', 'children': ['184']}; {'id': '184', 'type': 'None', 'children': []}, {'id': '185', 'type': 'if_statement', 'children': ['186', '189']}; {'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': 'is'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'ofsWidget'}; {'id': '188', 'type': 'None', 'children': []}, {'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': 'ofsWidget'}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': '_qteActiveWidget'}; {'id': '196', 'type': 'if_statement', 'children': ['197', '206']}, {'id': '197', 'type': 'boolean_operator', 'children': ['198', '202'], 'value': 'and'}; {'id': '198', 'type': 'parenthesized_expression', 'children': ['199'], 'value': '()'}, {'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': 'is'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'ofsWidget'}, {'id': '201', 'type': 'None', 'children': []}; {'id': '202', 'type': 'parenthesized_expression', 'children': ['203'], 'value': '()'}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': '=='}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'numSkip'}, {'id': '205', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'if_statement', 'children': ['208', '212']}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'qteIsQtmacsWidget'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'ofsWidget'}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'return_statement', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'ofsWidget'}, {'id': '215', 'type': 'try_statement', 'children': ['216', '226']}; {'id': '216', 'type': 'block', 'children': ['217']}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'}; {'id': '220', 'type': 'call', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'widList'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'ofsWidget'}; {'id': '226', 'type': 'except_clause', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'}; {'id': '232', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'}; {'id': '236', 'type': 'binary_operator', 'children': ['237', '241'], 'value': '%'}, {'id': '237', 'type': 'parenthesized_expression', 'children': ['238'], 'value': '()'}; {'id': '238', 'type': 'binary_operator', 'children': ['239', '240'], 'value': '+'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ofsIdx'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'numSkip'}, {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'widList'}, {'id': '245', 'type': 'return_statement', 'children': ['246']}; {'id': '246', 'type': 'subscript', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'widList'}
def qteNextWidget(self, numSkip: int=1, ofsWidget: QtGui.QWidget=None, skipVisible: bool=False, skipInvisible: bool=True, skipFocusable: bool=False, skipUnfocusable: bool=True): if not hasattr(ofsWidget, '_qteAdmin') and (ofsWidget is not None): msg = '<ofsWidget> was probably not added with <qteAddWidget>' msg += ' method because it lacks the <_qteAdmin> attribute.' raise QtmacsOtherError(msg) self.qteAutoremoveDeletedWidgets() widList = list(self._qteAdmin.widgetList) if not len(widList): if qteGetAppletFromWidget(self._qteActiveWidget) is self: return self._qteActiveWidget else: return None if skipInvisible: widList = [wid for wid in widList if wid.isVisible()] if skipVisible: widList = [wid for wid in widList if not wid.isVisible()] if skipFocusable: widList = [wid for wid in widList if not wid._qteAdmin.isFocusable] if skipUnfocusable: widList = [wid for wid in widList if wid._qteAdmin.isFocusable] if not len(widList): return None if ofsWidget is None: ofsWidget = self._qteActiveWidget if (ofsWidget is not None) and (numSkip == 0): if qteIsQtmacsWidget(ofsWidget): return ofsWidget try: ofsIdx = widList.index(ofsWidget) except ValueError: ofsIdx = 0 ofsIdx = (ofsIdx + numSkip) % len(widList) return widList[ofsIdx]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'qteMakeWidgetActive'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'QtGui'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'QWidget'}, {'id': '11', 'type': 'block', 'children': ['12', '24', '41', '56', '70', '76', '108', '119']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '23']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_qteActiveWidget'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'return_statement', 'children': []}; {'id': '24', 'type': 'if_statement', 'children': ['25', '31']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '30'], 'value': 'is'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'qteGetAppletFromWidget'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'block', 'children': ['32', '36']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '35', 'type': 'string', 'children': [], 'value': "'The specified widget is not inside the current applet.'"}; {'id': '36', 'type': 'raise_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'QtmacsOtherError'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '48']}; {'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', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'_qteAdmin'"}; {'id': '48', 'type': 'block', 'children': ['49', '55']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': '_qteActiveWidget'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '55', 'type': 'return_statement', 'children': []}; {'id': '56', 'type': 'if_statement', 'children': ['57', '62']}, {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'isQtmacsApplet'}; {'id': '62', 'type': 'block', 'children': ['63', '69']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': '_qteActiveWidget'}; {'id': '68', 'type': 'None', 'children': []}, {'id': '69', 'type': 'return_statement', 'children': []}; {'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': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'qteAutoremoveDeletedWidgets'}, {'id': '75', 'type': 'argument_list', 'children': []}; {'id': '76', 'type': 'if_statement', 'children': ['77', '84']}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'not'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'id': '79', 'type': 'attribute', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': '_qteAdmin'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'widgetList'}; {'id': '84', 'type': 'block', 'children': ['85', '89', '101', '107']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'Widget is not registered for this applet.'"}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '96']}, {'id': '91', 'type': 'attribute', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'qteLogger'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'stack_info'}; {'id': '100', 'type': 'True', 'children': []}, {'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': 'self'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': '_qteActiveWidget'}; {'id': '106', 'type': 'None', 'children': []}, {'id': '107', 'type': 'return_statement', 'children': []}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'qteSetWidgetFocusOrder'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'tuple', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': '_qteActiveWidget'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'widgetObj'}, {'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': 'self'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': '_qteActiveWidget'}
def qteMakeWidgetActive(self, widgetObj: QtGui.QWidget): if widgetObj is None: self._qteActiveWidget = None return if qteGetAppletFromWidget(widgetObj) is not self: msg = 'The specified widget is not inside the current applet.' raise QtmacsOtherError(msg) if not hasattr(widgetObj, '_qteAdmin'): self._qteActiveWidget = widgetObj return if widgetObj._qteAdmin.isQtmacsApplet: self._qteActiveWidget = None return self.qteAutoremoveDeletedWidgets() if widgetObj not in self._qteAdmin.widgetList: msg = 'Widget is not registered for this applet.' self.qteLogger.error(msg, stack_info=True) self._qteActiveWidget = None return self.qteSetWidgetFocusOrder((self._qteActiveWidget, widgetObj)) self._qteActiveWidget = widgetObj
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_result'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'result_class'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'prev_node'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'remember'}; {'id': '14', 'type': 'True', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'key_chunks'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'notify'}; {'id': '20', 'type': 'True', 'children': []}, {'id': '21', 'type': 'dictionary_splat_pattern', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '23', 'type': 'block', 'children': ['24', '44', '50', '69', '75', '100', '111', '131', '138', '174', '206']}; {'id': '24', 'type': 'function_definition', 'children': ['25', '26', '30']}, {'id': '25', 'type': 'function_name', 'children': [], 'value': 'canonicalize'}; {'id': '26', 'type': 'parameters', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '28', 'type': 'dictionary_splat_pattern', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'conditional_expression', 'children': ['33', '34', '37'], 'value': 'if'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'canonicalize'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'dictionary_splat', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'result_class'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '62', '68']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'canonicalize'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '60', 'type': 'dictionary_splat', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'canonicalize'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'prev_node'}; {'id': '66', 'type': 'dictionary_splat', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '72']}; {'id': '70', 'type': 'not_operator', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'remember'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '82']}, {'id': '77', 'type': 'subscript', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'history'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'result_class'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '92', '99']}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'canonicalize'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'include_nodes'}, {'id': '91', 'type': 'False', 'children': []}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'canonicalize'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'prev_node'}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'include_nodes'}; {'id': '98', 'type': 'False', 'children': []}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'key_chunks'}, {'id': '103', 'type': 'boolean_operator', 'children': ['104', '105'], 'value': 'or'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'key_chunks'}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'split_key'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'asymptotic_key_chunks'}; {'id': '114', 'type': 'generator_expression', 'children': ['115', '122']}, {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'key_chunks'}, {'id': '117', 'type': 'slice', 'children': ['118', '119']}; {'id': '118', 'type': 'colon', 'children': []}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '+'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'for_in_clause', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'xrange'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'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': 'key_chunks'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'event_keys'}; {'id': '134', 'type': 'list', 'children': ['135'], 'value': '[(False, key_chunks)]'}, {'id': '135', 'type': 'tuple', 'children': ['136', '137']}; {'id': '136', 'type': 'False', 'children': []}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'key_chunks'}; {'id': '138', 'type': 'for_statement', 'children': ['139', '140', '141']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': '_key_chunks'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'asymptotic_key_chunks'}, {'id': '141', 'type': 'block', 'children': ['142', '148', '165']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'exact'}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '=='}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '_key_chunks'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'key_chunks'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '161']}; {'id': '150', 'type': 'attribute', 'children': ['151', '160']}, {'id': '151', 'type': 'call', 'children': ['152', '157']}; {'id': '152', 'type': 'attribute', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'setdefault'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': '_key_chunks'}, {'id': '159', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'tuple', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'exact'}, {'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': 'event_keys'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'tuple', 'children': ['172', '173']}; {'id': '172', 'type': 'True', 'children': []}, {'id': '173', 'type': 'identifier', 'children': [], 'value': '_key_chunks'}; {'id': '174', 'type': 'if_statement', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'notify'}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'for_statement', 'children': ['178', '179', '180']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'event_key'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'event_keys'}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'try_statement', 'children': ['182', '194', '198']}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '186', 'type': 'call', 'children': ['187', '192']}, {'id': '187', 'type': 'attribute', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'event_key'}; {'id': '194', 'type': 'except_clause', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '196', 'type': 'block', 'children': ['197']}, {'id': '197', 'type': 'pass_statement', 'children': []}; {'id': '198', 'type': 'else_clause', 'children': ['199']}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '205', 'type': 'argument_list', 'children': []}; {'id': '206', 'type': 'return_statement', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'result'}
def make_result(self, result_class, node=None, prev_node=None, remember=True, key_chunks=None, notify=True, **kwargs): def canonicalize(node, **kwargs): return None if node is None else node.canonicalize(**kwargs) index = self.index result = result_class(canonicalize(node, **kwargs), canonicalize(prev_node, **kwargs), index) if not remember: return result self.history[index] = result_class( canonicalize(node, include_nodes=False), canonicalize(prev_node, include_nodes=False), index) key_chunks = key_chunks or split_key(node.key) asymptotic_key_chunks = (key_chunks[:x + 1] for x in xrange(len(key_chunks))) event_keys = [(False, key_chunks)] for _key_chunks in asymptotic_key_chunks: exact = _key_chunks == key_chunks self.indices.setdefault(_key_chunks, []).append((index, exact)) event_keys.append((True, _key_chunks)) if notify: for event_key in event_keys: try: event = self.events.pop(event_key) except KeyError: pass else: event.set() return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_class_frame_source'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'class_name'}, {'id': '5', 'type': 'block', 'children': ['6', '181']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '13']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'frame_info'}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'inspect'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '12', 'type': 'argument_list', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '54']}; {'id': '14', 'type': 'try_statement', 'children': ['15', '50']}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'with_statement', 'children': ['17', '28']}, {'id': '17', 'type': 'with_clause', 'children': ['18']}; {'id': '18', 'type': 'with_item', 'children': ['19']}, {'id': '19', 'type': 'as_pattern', 'children': ['20', '26']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'frame_info'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'as_pattern_target', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'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': 'src'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': '""'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'subscript', 'children': ['38', '43']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'fp'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'readlines'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'slice', 'children': ['44', '49']}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '48'], 'value': '-'}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'frame_info'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '49', 'type': 'colon', 'children': []}; {'id': '50', 'type': 'except_clause', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'continue_statement', 'children': []}; {'id': '54', 'type': 'if_statement', 'children': ['55', '67']}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '66']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': 'r"\\bclass\\b\\s+\\b{}\\b"'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'src'}, {'id': '67', 'type': 'block', 'children': ['68', '79', '88', '92', '96', '100', '104']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'reader'}, {'id': '71', 'type': 'attribute', 'children': ['72', '78']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'StringIO'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'src'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'readline'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'tokens'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'tokenize'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'generate_tokens'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'reader'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'source_tokens'}, {'id': '91', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'indent_level'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'base_indent_level'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'has_base_level'}, {'id': '103', 'type': 'False', 'children': []}; {'id': '104', 'type': 'for_statement', 'children': ['105', '111', '112']}, {'id': '105', 'type': 'pattern_list', 'children': ['106', '107', '108', '109', '110']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'tokens'}; {'id': '112', 'type': 'block', 'children': ['113', '122']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'source_tokens'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'tuple', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '128', '133', '169']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '=='}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'tokenize'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'INDENT'}; {'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': 'indent_level'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '133', 'type': 'elif_clause', 'children': ['134', '139']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '=='}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'tokenize'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'DEDENT'}, {'id': '139', 'type': 'block', 'children': ['140', '144']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'augmented_assignment', 'children': ['142', '143'], 'value': '-='}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'indent_level'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '144', 'type': 'if_statement', 'children': ['145', '150']}, {'id': '145', 'type': 'boolean_operator', 'children': ['146', '147'], 'value': 'and'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'has_base_level'}, {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': '<='}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'indent_level'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'base_indent_level'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'tuple', 'children': ['153', '159', '164']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'tokenize'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'untokenize'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'source_tokens'}, {'id': '159', 'type': 'attribute', 'children': ['160', '163']}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'frame_info'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'f_globals'}; {'id': '164', 'type': 'attribute', 'children': ['165', '168']}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'frame_info'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'f_locals'}, {'id': '169', 'type': 'elif_clause', 'children': ['170', '172']}; {'id': '170', 'type': 'not_operator', 'children': ['171']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'has_base_level'}; {'id': '172', 'type': 'block', 'children': ['173', '177']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'has_base_level'}; {'id': '176', 'type': 'True', 'children': []}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'base_indent_level'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'indent_level'}, {'id': '181', 'type': 'raise_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'string', 'children': [], 'value': '\'Unable to retrieve source for class "{}"\''}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}
def _get_class_frame_source(class_name): for frame_info in inspect.stack(): try: with open(frame_info[1]) as fp: src = "".join(fp.readlines()[frame_info[2] - 1 :]) except IOError: continue if re.search(r"\bclass\b\s+\b{}\b".format(class_name), src): reader = six.StringIO(src).readline tokens = tokenize.generate_tokens(reader) source_tokens = [] indent_level = 0 base_indent_level = 0 has_base_level = False for token, value, _, _, _ in tokens: source_tokens.append((token, value)) if token == tokenize.INDENT: indent_level += 1 elif token == tokenize.DEDENT: indent_level -= 1 if has_base_level and indent_level <= base_indent_level: return ( tokenize.untokenize(source_tokens), frame_info[0].f_globals, frame_info[0].f_locals, ) elif not has_base_level: has_base_level = True base_indent_level = indent_level raise TypeError( 'Unable to retrieve source for class "{}"'.format(class_name) )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_create_typed_object_meta'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'get_fset'}, {'id': '5', 'type': 'block', 'children': ['6', '45', '282']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '12']}, {'id': '7', 'type': 'function_name', 'children': [], 'value': '_get_fget'}; {'id': '8', 'type': 'parameters', 'children': ['9', '10', '11']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'private_attr'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '12', 'type': 'block', 'children': ['13', '43']}, {'id': '13', 'type': 'function_definition', 'children': ['14', '15', '17']}; {'id': '14', 'type': 'function_name', 'children': [], 'value': '_fget'}, {'id': '15', 'type': 'parameters', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'try_statement', 'children': ['19', '26']}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'private_attr'}; {'id': '26', 'type': 'except_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'raise_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'string', 'children': [], 'value': '"\'{}\' object has no attribute \'{}\'"'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '42']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '_get_type_name'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_fget'}, {'id': '45', 'type': 'class_definition', 'children': ['46', '47', '49']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_AnnotatedObjectMeta'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'function_definition', 'children': ['51', '52', '59']}, {'id': '51', 'type': 'function_name', 'children': [], 'value': '__new__'}; {'id': '52', 'type': 'parameters', 'children': ['53', '54', '55', '56', '57']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'mcs'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '57', 'type': 'dictionary_splat_pattern', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '59', 'type': 'block', 'children': ['60', '70', '85', '103', '115', '119', '210', '226', '232', '266']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': '"__annotations__"'}, {'id': '69', 'type': 'dictionary', 'children': []}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'use_comment_type_hints'}, {'id': '73', 'type': 'parenthesized_expression', 'children': ['74'], 'value': '()'}; {'id': '74', 'type': 'boolean_operator', 'children': ['75', '77'], 'value': 'and'}, {'id': '75', 'type': 'not_operator', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '84'], 'value': '!='}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'string', 'children': [], 'value': '"__module__"'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '85', 'type': 'if_statement', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'use_comment_type_hints'}, {'id': '87', 'type': 'block', 'children': ['88', '95']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'frame_source'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_get_class_frame_source'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'get_type_hints'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'list_splat', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'frame_source'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '111'], 'value': '+'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'typed_attrs'}; {'id': '118', 'type': 'dictionary', 'children': []}, {'id': '119', 'type': 'for_statement', 'children': ['120', '121', '122']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '122', 'type': 'block', 'children': ['123', '134']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '128']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'typed_attrs'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '134', 'type': 'if_statement', 'children': ['135', '142']}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': '_is_propertyable'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140', '141']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'names'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '142', 'type': 'block', 'children': ['143', '152', '165', '190']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'private_attr'}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'string', 'children': [], 'value': '"__{}"'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '152', 'type': 'if_statement', 'children': ['153', '156']}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': 'in'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '162']}, {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'typed_attrs'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'private_attr'}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '168', 'type': 'parenthesized_expression', 'children': ['169'], 'value': '()'}, {'id': '169', 'type': 'conditional_expression', 'children': ['170', '175', '187'], 'value': 'if'}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '175', 'type': 'boolean_operator', 'children': ['176', '182'], 'value': 'and'}; {'id': '176', 'type': 'boolean_operator', 'children': ['177', '179'], 'value': 'and'}, {'id': '177', 'type': 'not_operator', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'use_comment_type_hints'}, {'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'in'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '182', 'type': 'comparison_operator', 'children': ['183', '186'], 'value': 'is'}, {'id': '183', 'type': 'subscript', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '186', 'type': 'None', 'children': []}, {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'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': 'typed_attrs'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'property'}, {'id': '197', 'type': 'argument_list', 'children': ['198', '204']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': '_get_fget'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '202', '203']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'private_attr'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '204', 'type': 'call', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'get_fset'}; {'id': '206', 'type': 'argument_list', 'children': ['207', '208', '209']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'private_attr'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '213', 'type': 'list_comprehension', 'children': ['214', '215', '218']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '215', 'type': 'for_in_clause', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '218', 'type': 'if_clause', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': '_is_propertyable'}, {'id': '221', 'type': 'argument_list', 'children': ['222', '223', '224', '225']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'names'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'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': 'typed_attrs'}; {'id': '230', 'type': 'string', 'children': [], 'value': '"_tp__typed_properties"'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '237']}; {'id': '234', 'type': 'subscript', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'typed_attrs'}; {'id': '236', 'type': 'string', 'children': [], 'value': '"_tp__required_typed_properties"'}, {'id': '237', 'type': 'list_comprehension', 'children': ['238', '239', '242']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '239', 'type': 'for_in_clause', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '242', 'type': 'if_clause', 'children': ['243']}, {'id': '243', 'type': 'boolean_operator', 'children': ['244', '256'], 'value': 'and'}; {'id': '244', 'type': 'parenthesized_expression', 'children': ['245'], 'value': '()'}, {'id': '245', 'type': 'boolean_operator', 'children': ['246', '249'], 'value': 'or'}; {'id': '246', 'type': 'comparison_operator', 'children': ['247', '248'], 'value': 'not'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '249', 'type': 'boolean_operator', 'children': ['250', '255'], 'value': 'and'}; {'id': '250', 'type': 'comparison_operator', 'children': ['251', '254'], 'value': 'is'}, {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '254', 'type': 'None', 'children': []}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'use_comment_type_hints'}; {'id': '256', 'type': 'comparison_operator', 'children': ['257', '258'], 'value': 'not'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'NoneType'}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '264', '265']}, {'id': '261', 'type': 'subscript', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '264', 'type': 'string', 'children': [], 'value': '"__args__"'}, {'id': '265', 'type': 'tuple', 'children': []}; {'id': '266', 'type': 'return_statement', 'children': ['267']}, {'id': '267', 'type': 'call', 'children': ['268', '275']}; {'id': '268', 'type': 'attribute', 'children': ['269', '274']}, {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '271', 'type': 'argument_list', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': '_AnnotatedObjectMeta'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'mcs'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': '__new__'}, {'id': '275', 'type': 'argument_list', 'children': ['276', '277', '278', '279', '280']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'mcs'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'bases'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'typed_attrs'}; {'id': '280', 'type': 'dictionary_splat', 'children': ['281']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '282', 'type': 'return_statement', 'children': ['283']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': '_AnnotatedObjectMeta'}
def _create_typed_object_meta(get_fset): def _get_fget(attr, private_attr, type_): def _fget(self): try: return getattr(self, private_attr) except AttributeError: raise AttributeError( "'{}' object has no attribute '{}'".format( _get_type_name(type_), attr ) ) return _fget class _AnnotatedObjectMeta(type): def __new__( mcs, name, bases, attrs, **kwargs ): annotations = attrs.get("__annotations__", {}) use_comment_type_hints = ( not annotations and attrs.get("__module__") != __name__ ) if use_comment_type_hints: frame_source = _get_class_frame_source(name) annotations = get_type_hints(*frame_source) names = list(attrs) + list(annotations) typed_attrs = {} for attr in names: typed_attrs[attr] = attrs.get(attr) if _is_propertyable(names, attrs, annotations, attr): private_attr = "__{}".format(attr) if attr in attrs: typed_attrs[private_attr] = attrs[attr] type_ = ( Optional[annotations[attr]] if not use_comment_type_hints and attr in attrs and attrs[attr] is None else annotations[attr] ) typed_attrs[attr] = property( _get_fget(attr, private_attr, type_), get_fset(attr, private_attr, type_), ) properties = [ attr for attr in annotations if _is_propertyable(names, attrs, annotations, attr) ] typed_attrs["_tp__typed_properties"] = properties typed_attrs["_tp__required_typed_properties"] = [ attr for attr in properties if ( attr not in attrs or attrs[attr] is None and use_comment_type_hints ) and NoneType not in getattr(annotations[attr], "__args__", ()) ] return super(_AnnotatedObjectMeta, mcs).__new__( mcs, name, bases, typed_attrs, **kwargs ) return _AnnotatedObjectMeta
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_build_module_db'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '72']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'tdict'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'lambda', 'children': ['15']}, {'id': '15', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '16', 'type': 'for_statement', 'children': ['17', '20', '29']}, {'id': '17', 'type': 'pattern_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'callable_name'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'callable_dict'}; {'id': '20', 'type': 'call', 'children': ['21', '28']}, {'id': '21', 'type': 'attribute', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '_exh_obj'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'callables_db'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30', '38', '57']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '35']}; {'id': '32', 'type': 'pattern_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'line_no'}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'callable_dict'}, {'id': '37', 'type': 'string', 'children': [], 'value': '"code_id"'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'cname'}, {'id': '41', 'type': 'parenthesized_expression', 'children': ['42'], 'value': '()'}; {'id': '42', 'type': 'conditional_expression', 'children': ['43', '51', '56'], 'value': 'if'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'string', 'children': [], 'value': '"{cls_name}.__init__"'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cls_name'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'callable_name'}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '55'], 'value': '=='}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'callable_dict'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"type"'}, {'id': '55', 'type': 'string', 'children': [], 'value': '"class"'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'callable_name'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '64']}, {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'tdict'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'dictionary', 'children': ['66', '69']}; {'id': '66', 'type': 'pair', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cname'}, {'id': '69', 'type': 'pair', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': '"line"'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'line_no'}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '79']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'tdict'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '78', 'type': 'argument_list', 'children': []}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '87']}; {'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': '_module_obj_db'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '93']}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'tdict'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '95', 'type': 'lambda', 'children': ['96', '98']}; {'id': '96', 'type': 'lambda_parameters', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'idict'}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'idict'}
def _build_module_db(self): tdict = collections.defaultdict(lambda: []) for callable_name, callable_dict in self._exh_obj.callables_db.items(): fname, line_no = callable_dict["code_id"] cname = ( "{cls_name}.__init__".format(cls_name=callable_name) if callable_dict["type"] == "class" else callable_name ) tdict[fname].append({"name": cname, "line": line_no}) for fname in tdict.keys(): self._module_obj_db[fname] = sorted( tdict[fname], key=lambda idict: idict["line"] )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'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', '23', '35', '69', '75', '84', '185']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'newkeys'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'newkeys'"}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ignore'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': "'ignore'"}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'if_statement', 'children': ['36', '42', '48']}; {'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': 'args'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'ValueError'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'string', 'children': [], 'value': "'no ents given to Ent.merge()'"}; {'id': '48', 'type': 'elif_clause', 'children': ['49', '61']}, {'id': '49', 'type': 'not_operator', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '52', 'type': 'generator_expression', 'children': ['53', '58']}, {'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': 's'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Ent'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'raise_statement', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'concatenated_string', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'all positional arguments to Ent.merge() must '"}; {'id': '68', 'type': 'string', 'children': [], 'value': "'be instances of Ent'"}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ent'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'args'}; {'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': 'data'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ent'}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '91']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ent'}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '88', 'type': 'slice', 'children': ['89', '90']}, {'id': '89', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '90', 'type': 'colon', 'children': []}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'for_statement', 'children': ['93', '96', '103']}, {'id': '93', 'type': 'pattern_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '96', 'type': 'call', 'children': ['97', '102']}, {'id': '97', 'type': 'attribute', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'ent'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '102', 'type': 'argument_list', 'children': []}, {'id': '103', 'type': 'block', 'children': ['104', '110']}; {'id': '104', 'type': 'if_statement', 'children': ['105', '108']}, {'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'in'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ignore'}; {'id': '108', 'type': 'block', 'children': ['109']}, {'id': '109', 'type': 'continue_statement', 'children': []}; {'id': '110', 'type': 'if_statement', 'children': ['111', '116', '174']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'in'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '116', 'type': 'block', 'children': ['117', '125']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'v1'}; {'id': '120', 'type': 'subscript', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '125', 'type': 'if_statement', 'children': ['126', '135']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '131'], 'value': '=='}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'v1'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'if_statement', 'children': ['137', '142', '159']}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'v1'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'Ent'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '150']}, {'id': '145', 'type': 'subscript', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'merge'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156', '157']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'v1'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '157', 'type': 'dictionary_splat', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '159', 'type': 'else_clause', 'children': ['160']}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '168']}, {'id': '163', 'type': 'subscript', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '174', 'type': 'elif_clause', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'newkeys'}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '184']}, {'id': '179', 'type': 'subscript', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '185', 'type': 'return_statement', 'children': ['186']}
def merge(cls, *args, **kwargs): newkeys = bool(kwargs.get('newkeys', False)) ignore = kwargs.get('ignore', list()) if len(args) < 1: raise ValueError('no ents given to Ent.merge()') elif not all(isinstance(s, Ent) for s in args): raise ValueError('all positional arguments to Ent.merge() must ' 'be instances of Ent') ent = args[0] data = cls.load(ent) for ent in args[1:]: for key, value in ent.__dict__.items(): if key in ignore: continue if key in data.__dict__: v1 = data.__dict__[key] if type(value) == type(v1): if isinstance(v1, Ent): data.__dict__[key] = cls.merge(v1, value, **kwargs) else: data.__dict__[key] = cls.load(value) elif newkeys: data.__dict__[key] = value return data
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'diff'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'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', '23', '35', '69', '75', '81', '206']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'newkeys'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'newkeys'"}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ignore'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': "'ignore'"}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'if_statement', 'children': ['36', '42', '48']}; {'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': 'args'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '2'}; {'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': 'ValueError'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'string', 'children': [], 'value': "'less than two ents given to Ent.diff()'"}; {'id': '48', 'type': 'elif_clause', 'children': ['49', '61']}, {'id': '49', 'type': 'not_operator', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '52', 'type': 'generator_expression', 'children': ['53', '58']}, {'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': 's'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Ent'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'raise_statement', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'concatenated_string', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'all positional arguments to Ent.diff() must '"}; {'id': '68', 'type': 'string', 'children': [], 'value': "'be instances of Ent'"}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 's1'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'args'}; {'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': 'differences'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'Ent'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'for_statement', 'children': ['82', '83', '88']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 's2'}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '85', 'type': 'slice', 'children': ['86', '87']}; {'id': '86', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '87', 'type': 'colon', 'children': []}; {'id': '88', 'type': 'block', 'children': ['89', '202']}, {'id': '89', 'type': 'for_statement', 'children': ['90', '93', '100']}; {'id': '90', 'type': 'pattern_list', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'value'}, {'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': 's2'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '99', 'type': 'argument_list', 'children': []}; {'id': '100', 'type': 'block', 'children': ['101', '107']}, {'id': '101', 'type': 'if_statement', 'children': ['102', '105']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'in'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ignore'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'continue_statement', 'children': []}, {'id': '107', 'type': 'if_statement', 'children': ['108', '113', '186']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'in'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 's1'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '113', 'type': 'block', 'children': ['114', '122']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'v1'}, {'id': '117', 'type': 'subscript', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 's1'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '132']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '128'], 'value': '=='}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'v1'}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'if_statement', 'children': ['134', '139', '168']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'v1'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'Ent'}, {'id': '139', 'type': 'block', 'children': ['140', '152']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'delta'}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '149', '150']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'v1'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '150', 'type': 'dictionary_splat', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '152', 'type': 'if_statement', 'children': ['153', '159']}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '167']}; {'id': '162', 'type': 'subscript', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'differences'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '168', 'type': 'elif_clause', 'children': ['169', '172']}, {'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': '!='}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'v1'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '180']}, {'id': '175', 'type': 'subscript', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'differences'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '186', 'type': 'elif_clause', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'newkeys'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '196']}, {'id': '191', 'type': 'subscript', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'differences'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 's1'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 's2'}; {'id': '206', 'type': 'return_statement', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'differences'}
def diff(cls, *args, **kwargs): newkeys = bool(kwargs.get('newkeys', False)) ignore = kwargs.get('ignore', list()) if len(args) < 2: raise ValueError('less than two ents given to Ent.diff()') elif not all(isinstance(s, Ent) for s in args): raise ValueError('all positional arguments to Ent.diff() must ' 'be instances of Ent') s1 = args[0] differences = Ent() for s2 in args[1:]: for key, value in s2.__dict__.items(): if key in ignore: continue if key in s1.__dict__: v1 = s1.__dict__[key] if type(value) == type(v1): if isinstance(v1, Ent): delta = cls.diff(v1, value, **kwargs) if len(delta.__dict__): differences.__dict__[key] = delta elif v1 != value: differences.__dict__[key] = cls.load(value) elif newkeys: differences.__dict__[key] = cls.load(value) s1 = s2 return differences
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sorted_keys_items'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dobj'}, {'id': '5', 'type': 'block', 'children': ['6', '17']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dobj'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'yield', 'children': ['23']}, {'id': '23', 'type': 'expression_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dobj'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'}
def _sorted_keys_items(dobj): keys = sorted(dobj.keys()) for key in keys: yield key, dobj[key]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_or_create_exh_obj'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'full_cname'}; {'id': '6', 'type': 'False', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'callables_fname'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '16', '40']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'r'}; {'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': 'hasattr'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '__builtin__'}; {'id': '22', 'type': 'string', 'children': [], 'value': '"_EXH"'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'set_exh_obj'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ExHandle'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '34', '37']}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'full_cname'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'full_cname'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'callables_fname'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'callables_fname'}; {'id': '40', 'type': 'return_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'get_exh_obj'}, {'id': '43', 'type': 'argument_list', 'children': []}
def get_or_create_exh_obj(full_cname=False, exclude=None, callables_fname=None): r if not hasattr(__builtin__, "_EXH"): set_exh_obj( ExHandle( full_cname=full_cname, exclude=exclude, callables_fname=callables_fname ) ) return get_exh_obj()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_property_search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fobj'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '30', '41', '64', '75', '90', '109', '113', '202', '211', '224', '283']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'scontext'}; {'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': 'fobj'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'f_locals'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': '"self"'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'class_obj'}; {'id': '22', 'type': 'conditional_expression', 'children': ['23', '26', '29'], 'value': 'if'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'scontext'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'scontext'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'if_statement', 'children': ['31', '33']}, {'id': '31', 'type': 'not_operator', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'class_obj'}, {'id': '33', 'type': 'block', 'children': ['34', '39']}; {'id': '34', 'type': 'delete_statement', 'children': ['35']}, {'id': '35', 'type': 'expression_list', 'children': ['36', '37', '38']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'fobj'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'scontext'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'class_obj'}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'None', 'children': []}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'class_props'}; {'id': '44', 'type': 'list_comprehension', 'children': ['45', '48', '58']}, {'id': '45', 'type': 'tuple', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'member_name'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'member_obj'}; {'id': '48', 'type': 'for_in_clause', 'children': ['49', '52']}, {'id': '49', 'type': 'pattern_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'member_name'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'member_obj'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'inspect'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'getmembers'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'class_obj'}; {'id': '58', 'type': 'if_clause', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'member_obj'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'property'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '67']}, {'id': '65', 'type': 'not_operator', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'class_props'}, {'id': '67', 'type': 'block', 'children': ['68', '73']}; {'id': '68', 'type': 'delete_statement', 'children': ['69']}, {'id': '69', 'type': 'expression_list', 'children': ['70', '71', '72']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'fobj'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'scontext'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'class_obj'}, {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'None', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'class_file'}; {'id': '78', 'type': 'call', 'children': ['79', '87']}, {'id': '79', 'type': 'attribute', 'children': ['80', '86']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'inspect'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'getfile'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'class_obj'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'string', 'children': [], 'value': '".pyc"'}, {'id': '89', 'type': 'string', 'children': [], 'value': '".py"'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'class_name'}, {'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': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': '_callables_obj'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'get_callable_from_line'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'class_file'}, {'id': '101', 'type': 'subscript', 'children': ['102', '108']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'inspect'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'getsourcelines'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'class_obj'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'prop_actions_dicts'}; {'id': '112', 'type': 'dictionary', 'children': []}, {'id': '113', 'type': 'for_statement', 'children': ['114', '117', '118']}; {'id': '114', 'type': 'pattern_list', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'prop_name'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'prop_obj'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'class_props'}; {'id': '118', 'type': 'block', 'children': ['119', '132', '196']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'prop_dict'}; {'id': '122', 'type': 'dictionary', 'children': ['123', '126', '129']}, {'id': '123', 'type': 'pair', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': '"fdel"'}, {'id': '125', 'type': 'None', 'children': []}; {'id': '126', 'type': 'pair', 'children': ['127', '128']}, {'id': '127', 'type': 'string', 'children': [], 'value': '"fget"'}; {'id': '128', 'type': 'None', 'children': []}, {'id': '129', 'type': 'pair', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': '"fset"'}, {'id': '131', 'type': 'None', 'children': []}; {'id': '132', 'type': 'for_statement', 'children': ['133', '134', '135']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'prop_dict'}, {'id': '135', 'type': 'block', 'children': ['136', '144']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'action_obj'}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'prop_obj'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '144', 'type': 'if_statement', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'action_obj'}; {'id': '146', 'type': 'block', 'children': ['147', '160', '176']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '152']}, {'id': '149', 'type': 'pattern_list', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'prev_func_obj'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'next_func_obj'}; {'id': '152', 'type': 'tuple', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'action_obj'}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158', '159']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'action_obj'}; {'id': '158', 'type': 'string', 'children': [], 'value': '"__wrapped__"'}, {'id': '159', 'type': 'None', 'children': []}; {'id': '160', 'type': 'while_statement', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'next_func_obj'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '168']}, {'id': '165', 'type': 'pattern_list', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'prev_func_obj'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'next_func_obj'}; {'id': '168', 'type': 'tuple', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'next_func_obj'}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174', '175']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'next_func_obj'}; {'id': '174', 'type': 'string', 'children': [], 'value': '"__wrapped__"'}, {'id': '175', 'type': 'None', 'children': []}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'prop_dict'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '181', 'type': 'list', 'children': ['182', '189'], 'value': '[\n id(_get_func_code(action_obj)),\n id(_get_func_code(prev_func_obj)),\n ]'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': '_get_func_code'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'action_obj'}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': '_get_func_code'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'prev_func_obj'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '201']}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'prop_actions_dicts'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'prop_name'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'prop_dict'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'func_id'}, {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'fobj'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'f_code'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'desc_dict'}; {'id': '214', 'type': 'dictionary', 'children': ['215', '218', '221']}, {'id': '215', 'type': 'pair', 'children': ['216', '217']}; {'id': '216', 'type': 'string', 'children': [], 'value': '"fget"'}, {'id': '217', 'type': 'string', 'children': [], 'value': '"getter"'}; {'id': '218', 'type': 'pair', 'children': ['219', '220']}, {'id': '219', 'type': 'string', 'children': [], 'value': '"fset"'}; {'id': '220', 'type': 'string', 'children': [], 'value': '"setter"'}, {'id': '221', 'type': 'pair', 'children': ['222', '223']}; {'id': '222', 'type': 'string', 'children': [], 'value': '"fdel"'}, {'id': '223', 'type': 'string', 'children': [], 'value': '"deleter"'}; {'id': '224', 'type': 'for_statement', 'children': ['225', '228', '233']}, {'id': '225', 'type': 'pattern_list', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'prop_name'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'prop_actions_dict'}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'prop_actions_dicts'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '232', 'type': 'argument_list', 'children': []}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'for_statement', 'children': ['235', '238', '243']}, {'id': '235', 'type': 'pattern_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'action_name'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'action_id_list'}; {'id': '238', 'type': 'call', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'prop_actions_dict'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '242', 'type': 'argument_list', 'children': []}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'if_statement', 'children': ['245', '251']}, {'id': '245', 'type': 'boolean_operator', 'children': ['246', '247'], 'value': 'and'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'action_id_list'}, {'id': '247', 'type': 'parenthesized_expression', 'children': ['248'], 'value': '()'}; {'id': '248', 'type': 'comparison_operator', 'children': ['249', '250'], 'value': 'in'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'func_id'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'action_id_list'}, {'id': '251', 'type': 'block', 'children': ['252', '263', '269']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'prop_name'}, {'id': '255', 'type': 'call', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'list', 'children': ['261', '262'], 'value': '[class_name, prop_name]'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'prop_name'}, {'id': '263', 'type': 'delete_statement', 'children': ['264']}; {'id': '264', 'type': 'expression_list', 'children': ['265', '266', '267', '268']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'fobj'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'scontext'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'class_obj'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'class_props'}, {'id': '269', 'type': 'return_statement', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'string', 'children': [], 'value': '"{prop_name}({prop_action})"'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '274', 'type': 'argument_list', 'children': ['275', '278']}, {'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'prop_name'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'prop_name'}; {'id': '278', 'type': 'keyword_argument', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'prop_action'}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'desc_dict'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'action_name'}, {'id': '283', 'type': 'return_statement', 'children': ['284']}
def _property_search(self, fobj): scontext = fobj.f_locals.get("self", None) class_obj = scontext.__class__ if scontext is not None else None if not class_obj: del fobj, scontext, class_obj return None class_props = [ (member_name, member_obj) for member_name, member_obj in inspect.getmembers(class_obj) if isinstance(member_obj, property) ] if not class_props: del fobj, scontext, class_obj return None class_file = inspect.getfile(class_obj).replace(".pyc", ".py") class_name = self._callables_obj.get_callable_from_line( class_file, inspect.getsourcelines(class_obj)[1] ) prop_actions_dicts = {} for prop_name, prop_obj in class_props: prop_dict = {"fdel": None, "fget": None, "fset": None} for action in prop_dict: action_obj = getattr(prop_obj, action) if action_obj: prev_func_obj, next_func_obj = ( action_obj, getattr(action_obj, "__wrapped__", None), ) while next_func_obj: prev_func_obj, next_func_obj = ( next_func_obj, getattr(next_func_obj, "__wrapped__", None), ) prop_dict[action] = [ id(_get_func_code(action_obj)), id(_get_func_code(prev_func_obj)), ] prop_actions_dicts[prop_name] = prop_dict func_id = id(fobj.f_code) desc_dict = {"fget": "getter", "fset": "setter", "fdel": "deleter"} for prop_name, prop_actions_dict in prop_actions_dicts.items(): for action_name, action_id_list in prop_actions_dict.items(): if action_id_list and (func_id in action_id_list): prop_name = ".".join([class_name, prop_name]) del fobj, scontext, class_obj, class_props return "{prop_name}({prop_action})".format( prop_name=prop_name, prop_action=desc_dict[action_name] ) return None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_execute'}, {'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': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '317', '326', '354', '360', '411']}, {'id': '9', 'type': 'try_statement', 'children': ['10', '117', '177', '214', '240', '266']}; {'id': '10', 'type': 'block', 'children': ['11', '18', '24', '30', '36', '65', '76', '105', '111']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_create_context'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_authenticate'}, {'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': 'context'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_current_context'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_parse_args'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '53']}, {'id': '37', 'type': 'boolean_operator', 'children': ['38', '43', '44'], 'value': 'and'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'_before_handlers'"}, {'id': '43', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_before_handlers'}; {'id': '50', 'type': 'tuple', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'for_statement', 'children': ['55', '56', '59']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_before_handlers'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'handler_result'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': '_handle'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '93']}, {'id': '77', 'type': 'boolean_operator', 'children': ['78', '83', '84'], 'value': 'and'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'_after_handlers'"}, {'id': '83', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': '_after_handlers'}; {'id': '90', 'type': 'tuple', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'for_statement', 'children': ['95', '96', '99']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': '_after_handlers'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'context'}, {'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': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '_render'}; {'id': '110', 'type': 'argument_list', 'children': []}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '117', 'type': 'except_clause', 'children': ['118', '122']}; {'id': '118', 'type': 'as_pattern', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'AuthenticationError'}; {'id': '120', 'type': 'as_pattern_target', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '122', 'type': 'block', 'children': ['123', '148', '157', '169']}, {'id': '123', 'type': 'if_statement', 'children': ['124', '135', '142']}; {'id': '124', 'type': 'boolean_operator', 'children': ['125', '130'], 'value': 'and'}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '129', 'type': 'string', 'children': [], 'value': "'message'"}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '134'], 'value': 'is'}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '134', 'type': 'None', 'children': []}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'message'}; {'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': 'message'}, {'id': '147', 'type': 'string', 'children': [], 'value': '"You don\'t have permission to do that."'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'APIError'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'Forbidden'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': '_response_class'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'list_splat', 'children': ['166']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '176']}, {'id': '171', 'type': 'subscript', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '175', 'type': 'string', 'children': [], 'value': '"Content-Type"'}; {'id': '176', 'type': 'string', 'children': [], 'value': "'application/json'"}, {'id': '177', 'type': 'except_clause', 'children': ['178', '182']}; {'id': '178', 'type': 'as_pattern', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'ArgumentError'}; {'id': '180', 'type': 'as_pattern_target', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '182', 'type': 'block', 'children': ['183', '194', '206']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'APIError'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'UnprocessableEntity'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': '_response_class'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'list_splat', 'children': ['203']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '213']}; {'id': '208', 'type': 'subscript', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '212', 'type': 'string', 'children': [], 'value': '"Content-Type"'}, {'id': '213', 'type': 'string', 'children': [], 'value': "'application/json'"}; {'id': '214', 'type': 'except_clause', 'children': ['215', '219']}, {'id': '215', 'type': 'as_pattern', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'APIError'}, {'id': '217', 'type': 'as_pattern_target', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '219', 'type': 'block', 'children': ['220', '232']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': '_response_class'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'list_splat', 'children': ['229']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '239']}; {'id': '234', 'type': 'subscript', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '238', 'type': 'string', 'children': [], 'value': '"Content-Type"'}, {'id': '239', 'type': 'string', 'children': [], 'value': "'application/json'"}; {'id': '240', 'type': 'except_clause', 'children': ['241', '245']}, {'id': '241', 'type': 'as_pattern', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'PaleRaisedResponse'}, {'id': '243', 'type': 'as_pattern_target', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '245', 'type': 'block', 'children': ['246', '258']}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '249', 'type': 'call', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': '_response_class'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'list_splat', 'children': ['255']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'assignment', 'children': ['260', '265']}; {'id': '260', 'type': 'subscript', 'children': ['261', '264']}, {'id': '261', 'type': 'attribute', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '264', 'type': 'string', 'children': [], 'value': '"Content-Type"'}, {'id': '265', 'type': 'string', 'children': [], 'value': "'application/json'"}; {'id': '266', 'type': 'except_clause', 'children': ['267', '271']}, {'id': '267', 'type': 'as_pattern', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '269', 'type': 'as_pattern_target', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '271', 'type': 'block', 'children': ['272', '285', '297', '309']}; {'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': 'logging'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'exception'}, {'id': '277', 'type': 'argument_list', 'children': ['278', '279', '284']}; {'id': '278', 'type': 'string', 'children': [], 'value': '"Failed to handle Pale Endpoint %s: %r"'}, {'id': '279', 'type': 'attribute', 'children': ['280', '283']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'assignment', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '288', 'type': 'call', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'APIError'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}, {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'repr'}, {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '300', 'type': 'call', 'children': ['301', '304']}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': '_response_class'}; {'id': '304', 'type': 'argument_list', 'children': ['305']}, {'id': '305', 'type': 'list_splat', 'children': ['306']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '316']}, {'id': '311', 'type': 'subscript', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '315', 'type': 'string', 'children': [], 'value': '"Content-Type"'}; {'id': '316', 'type': 'string', 'children': [], 'value': "'application/json'"}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'assignment', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'allow_cors'}; {'id': '320', 'type': 'call', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '322', 'type': 'argument_list', 'children': ['323', '324', '325']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '324', 'type': 'string', 'children': [], 'value': '"_allow_cors"'}, {'id': '325', 'type': 'None', 'children': []}; {'id': '326', 'type': 'if_statement', 'children': ['327', '330', '339']}, {'id': '327', 'type': 'comparison_operator', 'children': ['328', '329'], 'value': 'is'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'allow_cors'}, {'id': '329', 'type': 'True', 'children': []}; {'id': '330', 'type': 'block', 'children': ['331']}, {'id': '331', 'type': 'expression_statement', 'children': ['332']}; {'id': '332', 'type': 'assignment', 'children': ['333', '338']}, {'id': '333', 'type': 'subscript', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '337', 'type': 'string', 'children': [], 'value': "'Access-Control-Allow-Origin'"}; {'id': '338', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '339', 'type': 'elif_clause', 'children': ['340', '345']}; {'id': '340', 'type': 'call', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '342', 'type': 'argument_list', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'allow_cors'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'basestring'}, {'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': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '352', 'type': 'string', 'children': [], 'value': "'Access-Control-Allow-Origin'"}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'allow_cors'}; {'id': '354', 'type': 'expression_statement', 'children': ['355']}, {'id': '355', 'type': 'assignment', 'children': ['356', '359']}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '360', 'type': 'try_statement', 'children': ['361', '392']}, {'id': '361', 'type': 'block', 'children': ['362']}; {'id': '362', 'type': 'if_statement', 'children': ['363', '379']}, {'id': '363', 'type': 'boolean_operator', 'children': ['364', '369', '370'], 'value': 'and'}; {'id': '364', 'type': 'call', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '366', 'type': 'argument_list', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '368', 'type': 'string', 'children': [], 'value': "'_after_response_handlers'"}, {'id': '369', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '370', 'type': 'call', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '372', 'type': 'argument_list', 'children': ['373', '376']}, {'id': '373', 'type': 'attribute', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '375', 'type': 'identifier', 'children': [], 'value': '_after_response_handlers'}; {'id': '376', 'type': 'tuple', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '379', 'type': 'block', 'children': ['380']}; {'id': '380', 'type': 'for_statement', 'children': ['381', '382', '385']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '382', 'type': 'attribute', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': '_after_response_handlers'}, {'id': '385', 'type': 'block', 'children': ['386']}; {'id': '386', 'type': 'expression_statement', 'children': ['387']}, {'id': '387', 'type': 'call', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '389', 'type': 'argument_list', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '392', 'type': 'except_clause', 'children': ['393', '397']}, {'id': '393', 'type': 'as_pattern', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '395', 'type': 'as_pattern_target', 'children': ['396']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '397', 'type': 'block', 'children': ['398', '410']}; {'id': '398', 'type': 'expression_statement', 'children': ['399']}, {'id': '399', 'type': 'call', 'children': ['400', '403']}; {'id': '400', 'type': 'attribute', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'exception'}, {'id': '403', 'type': 'argument_list', 'children': ['404', '405']}; {'id': '404', 'type': 'string', 'children': [], 'value': '"Failed to process _after_response_handlers for Endpoint %s"'}, {'id': '405', 'type': 'attribute', 'children': ['406', '409']}; {'id': '406', 'type': 'attribute', 'children': ['407', '408']}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '409', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '410', 'type': 'raise_statement', 'children': []}, {'id': '411', 'type': 'return_statement', 'children': ['412']}
def _execute(self, request, **kwargs): try: self._create_context(request) self._authenticate() context = get_current_context() self._parse_args() if hasattr(self, '_before_handlers') and \ isinstance(self._before_handlers, (list, tuple)): for handler in self._before_handlers: handler(context) context.handler_result = self._handle(context) if hasattr(self, '_after_handlers') and \ isinstance(self._after_handlers, (list, tuple)): for handler in self._after_handlers: handler(context) self._render() response = context.response except AuthenticationError as e: if hasattr(e, 'message') and e.message is not None: message = e.message else: message = "You don't have permission to do that." err = APIError.Forbidden(message) response = self._response_class(*err.response) response.headers["Content-Type"] = 'application/json' except ArgumentError as e: err = APIError.UnprocessableEntity(e.message) response = self._response_class(*err.response) response.headers["Content-Type"] = 'application/json' except APIError as e: response = self._response_class(*e.response) response.headers["Content-Type"] = 'application/json' except PaleRaisedResponse as r: response = self._response_class(*r.response) response.headers["Content-Type"] = 'application/json' except Exception as e: logging.exception("Failed to handle Pale Endpoint %s: %r", self.__class__.__name__, e) err = APIError.Exception(repr(e)) response = self._response_class(*err.response) response.headers["Content-Type"] = 'application/json' allow_cors = getattr(self, "_allow_cors", None) if allow_cors is True: response.headers['Access-Control-Allow-Origin'] = '*' elif isinstance(allow_cors, basestring): response.headers['Access-Control-Allow-Origin'] = allow_cors context.response = response try: if hasattr(self, '_after_response_handlers') and \ isinstance(self._after_response_handlers, (list, tuple)): for handler in self._after_response_handlers: handler(context, response) except Exception as e: logging.exception( "Failed to process _after_response_handlers for Endpoint %s", self.__class__.__name__) raise return response
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_entity_errors'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'property_name'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'schema_errors'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '24', '119', '203']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '21']}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '18'], 'value': 'and'}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'schema_errors'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29', '46', '65', '78']}, {'id': '29', 'type': 'if_statement', 'children': ['30', '35']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'not'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'property_name'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '43']}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'if_statement', 'children': ['47', '54']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'not'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'direct'"}, {'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': 'errors'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'property_name'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '64']}, {'id': '57', 'type': 'subscript', 'children': ['58', '63']}; {'id': '58', 'type': 'subscript', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'direct'"}; {'id': '64', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '72']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '71'], 'value': 'is'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}; {'id': '76', 'type': 'list', 'children': ['77'], 'value': '[direct_errors]'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}; {'id': '78', 'type': 'for_statement', 'children': ['79', '80', '81']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}, {'id': '81', 'type': 'block', 'children': ['82', '106']}; {'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': 'error'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'Error'}, {'id': '89', 'type': 'block', 'children': ['90', '94']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'Error must be of type {}'"}; {'id': '94', 'type': 'raise_statement', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'InvalidErrorType'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'Error'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'call', 'children': ['108', '117']}; {'id': '108', 'type': 'attribute', 'children': ['109', '116']}, {'id': '109', 'type': 'subscript', 'children': ['110', '115']}; {'id': '110', 'type': 'subscript', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '115', 'type': 'string', 'children': [], 'value': "'direct'"}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '123']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'is'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'schema_errors'}; {'id': '122', 'type': 'None', 'children': []}, {'id': '123', 'type': 'block', 'children': ['124', '137', '143', '160']}; {'id': '124', 'type': 'if_statement', 'children': ['125', '130']}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'schema_errors'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'schema_errors'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'schema_errors'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '137', 'type': 'if_statement', 'children': ['138', '140']}; {'id': '138', 'type': 'not_operator', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'schema_errors'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'return_statement', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '143', 'type': 'if_statement', 'children': ['144', '149']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'not'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'property_name'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '149', 'type': 'block', 'children': ['150']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '157']}; {'id': '152', 'type': 'subscript', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'if_statement', 'children': ['161', '168', '179']}, {'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': 'not'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'schema'"}, {'id': '163', 'type': 'subscript', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'property_name'}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '178']}, {'id': '171', 'type': 'subscript', 'children': ['172', '177']}; {'id': '172', 'type': 'subscript', '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': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '177', 'type': 'string', 'children': [], 'value': "'schema'"}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'schema_errors'}, {'id': '179', 'type': 'else_clause', 'children': ['180']}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '190']}, {'id': '183', 'type': 'subscript', 'children': ['184', '189']}; {'id': '184', 'type': 'subscript', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '189', 'type': 'string', 'children': [], 'value': "'schema'"}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'merge_errors'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '202']}, {'id': '195', 'type': 'subscript', 'children': ['196', '201']}; {'id': '196', 'type': 'subscript', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '201', 'type': 'string', 'children': [], 'value': "'schema'"}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'schema_errors'}, {'id': '203', 'type': 'return_statement', 'children': ['204']}
def add_entity_errors( self, property_name, direct_errors=None, schema_errors=None ): if direct_errors is None and schema_errors is None: return self if direct_errors is not None: if property_name not in self.errors: self.errors[property_name] = dict() if 'direct' not in self.errors[property_name]: self.errors[property_name]['direct'] = [] if type(direct_errors) is not list: direct_errors = [direct_errors] for error in direct_errors: if not isinstance(error, Error): err = 'Error must be of type {}' raise x.InvalidErrorType(err.format(Error)) self.errors[property_name]['direct'].append(error) if schema_errors is not None: if isinstance(schema_errors, Result): schema_errors = schema_errors.errors if not schema_errors: return self if property_name not in self.errors: self.errors[property_name] = dict() if 'schema' not in self.errors[property_name]: self.errors[property_name]['schema'] = schema_errors else: self.errors[property_name]['schema'] = self.merge_errors( self.errors[property_name]['schema'], schema_errors ) return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_collection_errors'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'property_name'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'collection_errors'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '24', '119', '264']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '21']}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '18'], 'value': 'and'}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'collection_errors'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29', '42', '59', '78']}, {'id': '29', 'type': 'if_statement', 'children': ['30', '36']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '35'], 'value': 'is'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}; {'id': '40', 'type': 'list', 'children': ['41'], 'value': '[direct_errors]'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '48']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'not'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '56']}, {'id': '51', 'type': 'subscript', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'property_name'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'if_statement', 'children': ['60', '67']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'not'}, {'id': '61', 'type': 'string', 'children': [], 'value': "'direct'"}; {'id': '62', 'type': 'subscript', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '77']}; {'id': '70', 'type': 'subscript', 'children': ['71', '76']}, {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'property_name'}; {'id': '76', 'type': 'string', 'children': [], 'value': "'direct'"}, {'id': '77', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '78', 'type': 'for_statement', 'children': ['79', '80', '81']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'direct_errors'}, {'id': '81', 'type': 'block', 'children': ['82', '106']}; {'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': 'error'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'Error'}, {'id': '89', 'type': 'block', 'children': ['90', '94']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'Error must be of type {}'"}; {'id': '94', 'type': 'raise_statement', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'InvalidErrorType'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'Error'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'call', 'children': ['108', '117']}; {'id': '108', 'type': 'attribute', 'children': ['109', '116']}, {'id': '109', 'type': 'subscript', 'children': ['110', '115']}; {'id': '110', 'type': 'subscript', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '115', 'type': 'string', 'children': [], 'value': "'direct'"}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'collection_errors'}, {'id': '121', 'type': 'block', 'children': ['122', '129', '147', '153', '170']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'enum'}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'collection_errors'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'errors_dict'}; {'id': '132', 'type': 'dictionary_comprehension', 'children': ['133', '136', '141']}, {'id': '133', 'type': 'pair', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '136', 'type': 'for_in_clause', 'children': ['137', '140']}, {'id': '137', 'type': 'pattern_list', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'enum'}, {'id': '141', 'type': 'if_clause', 'children': ['142']}; {'id': '142', 'type': 'not_operator', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '147', 'type': 'if_statement', 'children': ['148', '150']}; {'id': '148', 'type': 'not_operator', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'errors_dict'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'if_statement', 'children': ['154', '159']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'not'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'property_name'}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '167']}; {'id': '162', 'type': 'subscript', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '169', 'type': 'argument_list', 'children': []}; {'id': '170', 'type': 'if_statement', 'children': ['171', '178', '189']}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'not'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'collection'"}, {'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': 'errors'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'property_name'}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '188']}, {'id': '181', 'type': 'subscript', 'children': ['182', '187']}; {'id': '182', 'type': 'subscript', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'collection'"}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'errors_dict'}, {'id': '189', 'type': 'else_clause', 'children': ['190']}; {'id': '190', 'type': 'block', 'children': ['191', '201', '205']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'local'}; {'id': '194', 'type': 'subscript', 'children': ['195', '200']}, {'id': '195', 'type': 'subscript', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'property_name'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'collection'"}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'errors_dict'}, {'id': '205', 'type': 'for_statement', 'children': ['206', '209', '214']}; {'id': '206', 'type': 'pattern_list', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'block', 'children': ['215']}, {'id': '215', 'type': 'if_statement', 'children': ['216', '219', '232']}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': 'not'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'local'}, {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '231']}; {'id': '222', 'type': 'subscript', 'children': ['223', '230']}, {'id': '223', 'type': 'subscript', 'children': ['224', '229']}; {'id': '224', 'type': 'subscript', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '229', 'type': 'string', 'children': [], 'value': "'collection'"}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '232', 'type': 'else_clause', 'children': ['233']}, {'id': '233', 'type': 'block', 'children': ['234', '252']}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'merged'}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'merge_errors'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '247']}; {'id': '242', 'type': 'attribute', 'children': ['243', '246']}, {'id': '243', 'type': 'subscript', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'local'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '247', 'type': 'attribute', 'children': ['248', '251']}; {'id': '248', 'type': 'subscript', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '263']}; {'id': '254', 'type': 'subscript', 'children': ['255', '262']}, {'id': '255', 'type': 'subscript', 'children': ['256', '261']}; {'id': '256', 'type': 'subscript', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'property_name'}, {'id': '261', 'type': 'string', 'children': [], 'value': "'collection'"}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'merged'}; {'id': '264', 'type': 'return_statement', 'children': ['265']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'}
def add_collection_errors( self, property_name, direct_errors=None, collection_errors=None ): if direct_errors is None and collection_errors is None: return self if direct_errors is not None: if type(direct_errors) is not list: direct_errors = [direct_errors] if property_name not in self.errors: self.errors[property_name] = dict() if 'direct' not in self.errors[property_name]: self.errors[property_name]['direct'] = [] for error in direct_errors: if not isinstance(error, Error): err = 'Error must be of type {}' raise x.InvalidErrorType(err.format(Error)) self.errors[property_name]['direct'].append(error) if collection_errors: enum = enumerate(collection_errors) errors_dict = {i: e for i, e in enum if not bool(e)} if not errors_dict: return self if property_name not in self.errors: self.errors[property_name] = dict() if 'collection' not in self.errors[property_name]: self.errors[property_name]['collection'] = errors_dict else: local = self.errors[property_name]['collection'] remote = errors_dict for index, result in remote.items(): if index not in local: self.errors[property_name]['collection'][index] = result else: merged = self.merge_errors( local[index].errors, remote[index].errors ) self.errors[property_name]['collection'][index] = merged return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_errors'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'errors_local'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'errors_remote'}, {'id': '7', 'type': 'block', 'children': ['8', '304']}; {'id': '8', 'type': 'for_statement', 'children': ['9', '10', '11']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'errors_remote'}, {'id': '11', 'type': 'block', 'children': ['12', '26', '32', '45', '51', '64', '109', '113', '117', '138', '159', '177', '199', '228']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'not'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'errors_local'}; {'id': '16', 'type': 'block', 'children': ['17', '25']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '22']}, {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'errors_local'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'errors_remote'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '25', 'type': 'continue_statement', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'local'}, {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'errors_local'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'local'}, {'id': '35', 'type': 'conditional_expression', 'children': ['36', '39', '44'], 'value': 'if'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'local'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'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': 'local'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'local'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'errors_remote'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '54', 'type': 'conditional_expression', 'children': ['55', '58', '63'], 'value': 'if'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'remote'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'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': 'remote'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'Result'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '74']}, {'id': '65', 'type': 'not_operator', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'local'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '74', 'type': 'block', 'children': ['75', '79', '83']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'Type mismatch on property [{}] when merging errors. '"}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'augmented_assignment', 'children': ['81', '82'], 'value': '+='}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'Unable to merge [{}] into [{}]'"}, {'id': '83', 'type': 'raise_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'UnableToMergeResultsType'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95', '101']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'errors_remote'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'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': 'errors'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'mismatch'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'Unable to merge nested entity errors with nested '"}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'augmented_assignment', 'children': ['115', '116'], 'value': '+='}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'mismatch'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'collection errors on property [{}]'"}, {'id': '117', 'type': 'if_statement', 'children': ['118', '125']}; {'id': '118', 'type': 'boolean_operator', 'children': ['119', '122'], 'value': 'and'}, {'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': 'in'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'schema'"}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'local'}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'in'}, {'id': '123', 'type': 'string', 'children': [], 'value': "'collection'"}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'remote'}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'raise_statement', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'UnableToMergeResultsType'}, {'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': 'mismatch'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '146']}, {'id': '139', 'type': 'boolean_operator', 'children': ['140', '143'], 'value': 'and'}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'in'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'collection'"}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'local'}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'in'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'schema'"}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'raise_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'UnableToMergeResultsType'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'mismatch'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '159', 'type': 'if_statement', 'children': ['160', '166']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '165'], 'value': 'is'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'remote'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '166', 'type': 'block', 'children': ['167', '176']}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '174']}, {'id': '169', 'type': 'attribute', 'children': ['170', '173']}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'errors_local'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '176', 'type': 'continue_statement', 'children': []}, {'id': '177', 'type': 'if_statement', 'children': ['178', '185']}; {'id': '178', 'type': 'boolean_operator', 'children': ['179', '182'], 'value': 'and'}, {'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'in'}; {'id': '180', 'type': 'string', 'children': [], 'value': "'direct'"}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'in'}, {'id': '183', 'type': 'string', 'children': [], 'value': "'direct'"}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'local'}, {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'call', 'children': ['188', '195']}; {'id': '188', 'type': 'attribute', 'children': ['189', '194']}, {'id': '189', 'type': 'subscript', 'children': ['190', '193']}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'errors_local'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '193', 'type': 'string', 'children': [], 'value': "'direct'"}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'subscript', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '198', 'type': 'string', 'children': [], 'value': "'direct'"}, {'id': '199', 'type': 'if_statement', 'children': ['200', '207']}; {'id': '200', 'type': 'boolean_operator', 'children': ['201', '204'], 'value': 'and'}, {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'in'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'schema'"}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': 'in'}, {'id': '205', 'type': 'string', 'children': [], 'value': "'schema'"}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'local'}, {'id': '207', 'type': 'block', 'children': ['208']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '215']}; {'id': '210', 'type': 'subscript', 'children': ['211', '214']}, {'id': '211', 'type': 'subscript', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'errors_local'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'schema'"}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'merge_errors'}, {'id': '219', 'type': 'argument_list', 'children': ['220', '225']}; {'id': '220', 'type': 'subscript', 'children': ['221', '224']}, {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'errors_local'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '224', 'type': 'string', 'children': [], 'value': "'schema'"}, {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'remote'}, {'id': '227', 'type': 'string', 'children': [], 'value': "'schema'"}; {'id': '228', 'type': 'if_statement', 'children': ['229', '236']}, {'id': '229', 'type': 'boolean_operator', 'children': ['230', '233'], 'value': 'and'}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '232'], 'value': 'in'}, {'id': '231', 'type': 'string', 'children': [], 'value': "'collection'"}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'remote'}, {'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': 'in'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'collection'"}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'local'}; {'id': '236', 'type': 'block', 'children': ['237']}, {'id': '237', 'type': 'for_statement', 'children': ['238', '241', '248']}; {'id': '238', 'type': 'pattern_list', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '241', 'type': 'call', 'children': ['242', '247']}; {'id': '242', 'type': 'attribute', 'children': ['243', '246']}, {'id': '243', 'type': 'subscript', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'remote'}, {'id': '245', 'type': 'string', 'children': [], 'value': "'collection'"}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '247', 'type': 'argument_list', 'children': []}; {'id': '248', 'type': 'block', 'children': ['249']}, {'id': '249', 'type': 'if_statement', 'children': ['250', '255', '266']}; {'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': 'not'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '252', 'type': 'subscript', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'local'}; {'id': '254', 'type': 'string', 'children': [], 'value': "'collection'"}, {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '265']}; {'id': '258', 'type': 'subscript', 'children': ['259', '264']}, {'id': '259', 'type': 'subscript', 'children': ['260', '263']}; {'id': '260', 'type': 'subscript', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'errors_local'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '263', 'type': 'string', 'children': [], 'value': "'collection'"}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '266', 'type': 'else_clause', 'children': ['267']}, {'id': '267', 'type': 'block', 'children': ['268', '294']}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'merged'}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'merge_errors'}, {'id': '275', 'type': 'argument_list', 'children': ['276', '285']}; {'id': '276', 'type': 'attribute', 'children': ['277', '284']}, {'id': '277', 'type': 'subscript', 'children': ['278', '283']}; {'id': '278', 'type': 'subscript', 'children': ['279', '282']}, {'id': '279', 'type': 'subscript', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'errors_local'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '282', 'type': 'string', 'children': [], 'value': "'collection'"}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '285', 'type': 'attribute', 'children': ['286', '293']}; {'id': '286', 'type': 'subscript', 'children': ['287', '292']}, {'id': '287', 'type': 'subscript', 'children': ['288', '291']}; {'id': '288', 'type': 'subscript', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'errors_remote'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '291', 'type': 'string', 'children': [], 'value': "'collection'"}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}, {'id': '295', 'type': 'assignment', 'children': ['296', '303']}; {'id': '296', 'type': 'subscript', 'children': ['297', '302']}, {'id': '297', 'type': 'subscript', 'children': ['298', '301']}; {'id': '298', 'type': 'subscript', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'errors_local'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '301', 'type': 'string', 'children': [], 'value': "'collection'"}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'merged'}; {'id': '304', 'type': 'return_statement', 'children': ['305']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'errors_local'}
def merge_errors(self, errors_local, errors_remote): for prop in errors_remote: if prop not in errors_local: errors_local[prop] = errors_remote[prop] continue local = errors_local[prop] local = local.errors if isinstance(local, Result) else local remote = errors_remote[prop] remote = remote.errors if isinstance(remote, Result) else remote if not isinstance(local, type(remote)): msg = 'Type mismatch on property [{}] when merging errors. ' msg += 'Unable to merge [{}] into [{}]' raise x.UnableToMergeResultsType(msg.format( prop, type(errors_remote[prop]), type(self.errors[prop]) )) mismatch = 'Unable to merge nested entity errors with nested ' mismatch += 'collection errors on property [{}]' if 'schema' in local and 'collection' in remote: raise x.UnableToMergeResultsType(mismatch.format(prop)) if 'collection' in local and 'schema' in remote: raise x.UnableToMergeResultsType(mismatch.format(prop)) if type(remote) is list: errors_local[prop].extend(remote) continue if 'direct' in remote and 'direct' in local: errors_local[prop]['direct'].extend(remote['direct']) if 'schema' in remote and 'schema' in local: errors_local[prop]['schema'] = self.merge_errors( errors_local[prop]['schema'], remote['schema'] ) if 'collection' in remote and 'collection' in local: for index, result in remote['collection'].items(): if index not in local['collection']: errors_local[prop]['collection'][index] = result else: merged = self.merge_errors( errors_local[prop]['collection'][index].errors, errors_remote[prop]['collection'][index].errors, ) errors_local[prop]['collection'][index] = merged return errors_local
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cursorPositionChangedEvent'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '22', '30', '41', '48', '59', '84', '92', '103', '161', '179', '188', '196', '202', '210']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sender'}, {'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': 'tc'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'textCursor'}, {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'origin'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'tc'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'position'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'expression_statement', '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': 'qteWidget'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'cursorPositionChanged'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'disconnect'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'cursorPositionChangedEvent'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'qteRemoveHighlighting'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'cursorPositionChanged'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'connect'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'cursorPositionChangedEvent'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '70', '72']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '>='}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'origin'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'toPlainText'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'return_statement', 'children': []}; {'id': '72', 'type': 'else_clause', 'children': ['73']}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '77', 'type': 'subscript', 'children': ['78', '83']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'toPlainText'}; {'id': '82', 'type': 'argument_list', 'children': []}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'origin'}; {'id': '84', 'type': 'if_statement', 'children': ['85', '90']}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'not'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'charToHighlight'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'return_statement', 'children': []}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'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': 'qteWidget'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'cursorPositionChanged'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'disconnect'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'cursorPositionChangedEvent'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '111', '136']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '=='}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '106', 'type': 'subscript', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'charToHighlight'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '111', 'type': 'block', 'children': ['112', '116']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'origin'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '119', 'type': 'call', 'children': ['120', '127']}; {'id': '120', 'type': 'attribute', 'children': ['121', '126']}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'toPlainText'}, {'id': '125', 'type': 'argument_list', 'children': []}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '133']}; {'id': '128', 'type': 'subscript', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'charToHighlight'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '+'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '136', 'type': 'else_clause', 'children': ['137']}, {'id': '137', 'type': 'block', 'children': ['138', '142']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'origin'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '145', 'type': 'call', 'children': ['146', '153']}; {'id': '146', 'type': 'attribute', 'children': ['147', '152']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'toPlainText'}, {'id': '151', 'type': 'argument_list', 'children': []}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'rfind'}, {'id': '153', 'type': 'argument_list', 'children': ['154', '159', '160']}; {'id': '154', 'type': 'subscript', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'charToHighlight'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'oldCharFormats'}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'highlightCharacters'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '170', '173', '178']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}; {'id': '170', 'type': 'tuple', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '173', 'type': 'attribute', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'QtCore'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'Qt'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'blue'}; {'id': '178', 'type': 'integer', 'children': [], 'value': '100'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'qteMacroData'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'matchingPositions'}, {'id': '193', 'type': 'tuple', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'oldCharFormats'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'oldCharFormats'}; {'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': 'self'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'qteSaveMacroData'}, {'id': '207', 'type': 'argument_list', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'call', 'children': ['212', '217']}; {'id': '212', 'type': 'attribute', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'qteWidget'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'cursorPositionChanged'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'connect'}, {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'}
def cursorPositionChangedEvent(self): qteWidget = self.sender() tc = qteWidget.textCursor() origin = tc.position() qteWidget.cursorPositionChanged.disconnect( self.cursorPositionChangedEvent) self.qteRemoveHighlighting(qteWidget) qteWidget.cursorPositionChanged.connect( self.cursorPositionChangedEvent) if origin >= len(qteWidget.toPlainText()): return else: char = qteWidget.toPlainText()[origin] if char not in self.charToHighlight: return qteWidget.cursorPositionChanged.disconnect( self.cursorPositionChangedEvent) if char == self.charToHighlight[0]: start = origin stop = qteWidget.toPlainText().find(self.charToHighlight[1], start + 1) else: stop = origin start = qteWidget.toPlainText().rfind(self.charToHighlight[0], 0, stop) oldCharFormats = self.highlightCharacters(qteWidget, (start, stop), QtCore.Qt.blue, 100) data = self.qteMacroData(qteWidget) data.matchingPositions = (start, stop) data.oldCharFormats = oldCharFormats self.qteSaveMacroData(data, qteWidget) qteWidget.cursorPositionChanged.connect( self.cursorPositionChangedEvent)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'scenarios'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'generate_seed'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '16', '28', '75', '79', '83', '142', '157', '186', '190', '254', '262', '270']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'seed'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'prime_numbers'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sweeps_all'}, {'id': '19', 'type': 'call', 'children': ['20', '27']}; {'id': '20', 'type': 'attribute', 'children': ['21', '26']}, {'id': '21', 'type': 'subscript', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'experiment'}, {'id': '25', 'type': 'string', 'children': [], 'value': '"sweeps"'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'if_statement', 'children': ['29', '34', '67']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'in'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"combinations"'}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'if_statement', 'children': ['36', '45', '57']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '44']}, {'id': '39', 'type': 'subscript', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'experiment'}, {'id': '43', 'type': 'string', 'children': [], 'value': '"combinations"'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'list'}, {'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': 'combinations_in_experiment'}, {'id': '49', 'type': 'dictionary', 'children': ['50']}; {'id': '50', 'type': 'pair', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': '" "'}; {'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': 'experiment'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"combinations"'}, {'id': '57', 'type': 'else_clause', 'children': ['58']}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'combinations_in_experiment'}; {'id': '62', 'type': 'subscript', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '66', 'type': 'string', 'children': [], 'value': '"combinations"'}, {'id': '67', 'type': 'else_clause', 'children': ['68']}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'combinations_in_experiment'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '74', 'type': 'argument_list', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'all_combinations_sweeps'}; {'id': '78', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'all_combinations'}; {'id': '82', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '83', 'type': 'for_statement', 'children': ['84', '87', '92']}; {'id': '84', 'type': 'pattern_list', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'combinations_'}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'combinations_in_experiment'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'block', 'children': ['93', '122', '133']}, {'id': '93', 'type': 'if_statement', 'children': ['94', '96', '106']}; {'id': '94', 'type': 'not_operator', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'combinations_'}; {'id': '96', 'type': 'block', 'children': ['97', '101']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'combinations_sweeps'}; {'id': '100', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'combinations'}; {'id': '104', 'type': 'list', 'children': ['105'], 'value': '[[]]'}, {'id': '105', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '106', 'type': 'else_clause', 'children': ['107']}, {'id': '107', 'type': 'block', 'children': ['108', '114']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'combinations_sweeps'}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'combinations_'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'combinations'}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'combinations_'}, {'id': '119', 'type': 'slice', 'children': ['120', '121']}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '121', 'type': 'colon', 'children': []}; {'id': '122', 'type': 'for_statement', 'children': ['123', '124', '125']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'combinations_sweeps'}, {'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': 'all_combinations_sweeps'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'item'}, {'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': 'all_combinations'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'tuple', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'combinations_sweeps'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'combinations'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'sweeps_fully_factorial'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'binary_operator', 'children': ['149', '153'], 'value': '-'}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'sweeps_all'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'all_combinations_sweeps'}, {'id': '157', 'type': 'for_statement', 'children': ['158', '159', '160']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'sweep'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'sweeps_fully_factorial'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'all_combinations'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'tuple', 'children': ['168', '170']}; {'id': '168', 'type': 'list', 'children': ['169'], 'value': '[sweep]'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'sweep'}; {'id': '170', 'type': 'list_comprehension', 'children': ['171', '173']}, {'id': '171', 'type': 'list', 'children': ['172'], 'value': '[x]'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '173', 'type': 'for_in_clause', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '175', 'type': 'call', 'children': ['176', '185']}; {'id': '176', 'type': 'attribute', 'children': ['177', '184']}, {'id': '177', 'type': 'subscript', 'children': ['178', '183']}; {'id': '178', 'type': 'subscript', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '182', 'type': 'string', 'children': [], 'value': '"sweeps"'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'sweep'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '185', 'type': 'argument_list', 'children': []}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'red_iter'}, {'id': '189', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '190', 'type': 'while_statement', 'children': ['191', '197']}, {'id': '191', 'type': 'comparison_operator', 'children': ['192', '196'], 'value': '>'}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'all_combinations'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '197', 'type': 'block', 'children': ['198', '204', '210', '220', '237', '250']}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'comb1'}, {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'all_combinations'}, {'id': '203', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'comb2'}, {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'all_combinations'}, {'id': '209', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'new_sweeps'}, {'id': '213', 'type': 'binary_operator', 'children': ['214', '217'], 'value': '+'}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'comb1'}; {'id': '216', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '217', 'type': 'subscript', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'comb2'}, {'id': '219', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'new_combinations'}, {'id': '223', 'type': 'list_comprehension', 'children': ['224', '227', '232']}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '226'], 'value': '+'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '227', 'type': 'for_in_clause', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '229', 'type': 'subscript', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'comb1'}, {'id': '231', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '232', 'type': 'for_in_clause', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '234', 'type': 'subscript', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'comb2'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'all_combinations'}; {'id': '240', 'type': 'binary_operator', 'children': ['241', '245'], 'value': '+'}, {'id': '241', 'type': 'list', 'children': ['242'], 'value': '[(new_sweeps, new_combinations)]'}; {'id': '242', 'type': 'tuple', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'new_sweeps'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'new_combinations'}, {'id': '245', 'type': 'subscript', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'all_combinations'}, {'id': '247', 'type': 'slice', 'children': ['248', '249']}; {'id': '248', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '249', 'type': 'colon', 'children': []}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'augmented_assignment', 'children': ['252', '253'], 'value': '+='}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'red_iter'}, {'id': '253', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'sweep_names'}, {'id': '257', 'type': 'subscript', 'children': ['258', '261']}; {'id': '258', 'type': 'subscript', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'all_combinations'}; {'id': '260', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '261', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'assignment', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'combinations'}, {'id': '265', 'type': 'subscript', 'children': ['266', '269']}; {'id': '266', 'type': 'subscript', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'all_combinations'}; {'id': '268', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '269', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '270', 'type': 'for_statement', 'children': ['271', '272', '273']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'combination'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'combinations'}, {'id': '273', 'type': 'block', 'children': ['274', '292', '305', '343']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'assignment', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'scenario'}, {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'Scenario'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '284']}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': '_apply_combination'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '290', '291']}, {'id': '285', 'type': 'subscript', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'experiment'}, {'id': '289', 'type': 'string', 'children': [], 'value': '"base"'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'sweep_names'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'combination'}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'scenario'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '297', 'type': 'call', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'call', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '302', 'type': 'argument_list', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'sweep_names'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'combination'}, {'id': '305', 'type': 'if_statement', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'generate_seed'}, {'id': '307', 'type': 'block', 'children': ['308']}; {'id': '308', 'type': 'if_statement', 'children': ['309', '314', '335']}, {'id': '309', 'type': 'comparison_operator', 'children': ['310', '311'], 'value': 'in'}; {'id': '310', 'type': 'string', 'children': [], 'value': '"@seed@"'}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'scenario'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'xml'}; {'id': '314', 'type': 'block', 'children': ['315']}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'assignment', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'scenario'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'xml'}; {'id': '320', 'type': 'call', 'children': ['321', '326']}, {'id': '321', 'type': 'attribute', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'scenario'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'xml'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '326', 'type': 'argument_list', 'children': ['327', '328']}, {'id': '327', 'type': 'string', 'children': [], 'value': '"@seed@"'}; {'id': '328', 'type': 'call', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}, {'id': '331', 'type': 'call', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '333', 'type': 'argument_list', 'children': ['334']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'seed'}, {'id': '335', 'type': 'else_clause', 'children': ['336']}; {'id': '336', 'type': 'block', 'children': ['337']}, {'id': '337', 'type': 'raise_statement', 'children': ['338']}; {'id': '338', 'type': 'parenthesized_expression', 'children': ['339'], 'value': '()'}, {'id': '339', 'type': 'call', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}, {'id': '341', 'type': 'argument_list', 'children': ['342']}; {'id': '342', 'type': 'string', 'children': [], 'value': '"@seed@ placeholder is not found"'}, {'id': '343', 'type': 'expression_statement', 'children': ['344']}; {'id': '344', 'type': 'yield', 'children': ['345']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'scenario'}
def scenarios(self, generate_seed=False): seed = prime_numbers(1000) sweeps_all = self.experiment["sweeps"].keys() if "combinations" in self.experiment: if isinstance(self.experiment["combinations"], list): combinations_in_experiment = {" ": self.experiment["combinations"]} else: combinations_in_experiment = self.experiment["combinations"] else: combinations_in_experiment = dict() all_combinations_sweeps = [] all_combinations = [] for key, combinations_ in combinations_in_experiment.items(): if not combinations_: combinations_sweeps = [] combinations = [[]] else: combinations_sweeps = combinations_[0] combinations = combinations_[1:] for item in combinations_sweeps: all_combinations_sweeps.append(item) all_combinations.append((combinations_sweeps, combinations)) sweeps_fully_factorial = list(set(sweeps_all) - set(all_combinations_sweeps)) for sweep in sweeps_fully_factorial: all_combinations.append(([sweep], [[x] for x in self.experiment["sweeps"][sweep].keys()])) red_iter = 0 while len(all_combinations) > 1: comb1 = all_combinations[0] comb2 = all_combinations[1] new_sweeps = comb1[0] + comb2[0] new_combinations = [x+y for x in comb1[1] for y in comb2[1]] all_combinations = [(new_sweeps, new_combinations)] + all_combinations[2:] red_iter += 1 sweep_names = all_combinations[0][0] combinations = all_combinations[0][1] for combination in combinations: scenario = Scenario(self._apply_combination(self.experiment["base"], sweep_names, combination)) scenario.parameters = dict(zip(sweep_names, combination)) if generate_seed: if "@seed@" in scenario.xml: scenario.xml = scenario.xml.replace("@seed@", str(next(seed))) else: raise(RuntimeError("@seed@ placeholder is not found")) yield scenario
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'subdict_by_keys'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'dictionary_comprehension', 'children': ['9', '14']}, {'id': '9', 'type': 'pair', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '11', 'type': 'subscript', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '14', 'type': 'for_in_clause', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '16', 'type': 'call', 'children': ['17', '23']}, {'id': '17', 'type': 'attribute', 'children': ['18', '22']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'intersection'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'keys'}
def subdict_by_keys(dict_obj, keys): return {k: dict_obj[k] for k in set(keys).intersection(dict_obj.keys())}
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'deep_merge_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '6', 'type': 'block', 'children': ['7', '24', '33', '70']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '21']}; {'id': '8', 'type': 'boolean_operator', 'children': ['9', '15'], 'value': 'or'}, {'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': 'base'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'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': 'priority'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '33', 'type': 'for_statement', 'children': ['34', '35', '40']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'if_statement', 'children': ['42', '45', '60']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '51']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'deep_merge_dict'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'priority'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '60', 'type': 'else_clause', 'children': ['61']}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '67']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'priority'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'result'}
def deep_merge_dict(base, priority): if not isinstance(base, dict) or not isinstance(priority, dict): return priority result = copy.deepcopy(base) for key in priority.keys(): if key in base: result[key] = deep_merge_dict(base[key], priority[key]) else: result[key] = priority[key] return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'norm_int_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'int_dict'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '25', '39']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'norm_dict'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'int_dict'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'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': 'val_sum'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'norm_dict'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'norm_dict'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '34']}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'norm_dict'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '34', 'type': 'binary_operator', 'children': ['35', '38'], 'value': '/'}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'norm_dict'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'val_sum'}, {'id': '39', 'type': 'return_statement', 'children': ['40']}
def norm_int_dict(int_dict): norm_dict = int_dict.copy() val_sum = sum(norm_dict.values()) for key in norm_dict: norm_dict[key] = norm_dict[key] / val_sum return norm_dict
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sum_num_dicts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dicts'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'normalize'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '13', '37', '45']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sum_dict'}; {'id': '12', 'type': 'dictionary', 'children': []}, {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dicti'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'dicts'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'dicti'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '26']}, {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sum_dict'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '34'], 'value': '+'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sum_dict'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '33', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dicti'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'normalize'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'return_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'norm_int_dict'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sum_dict'}, {'id': '45', 'type': 'return_statement', 'children': ['46']}
def sum_num_dicts(dicts, normalize=False): sum_dict = {} for dicti in dicts: for key in dicti: sum_dict[key] = sum_dict.get(key, 0) + dicti[key] if normalize: return norm_int_dict(sum_dict) return sum_dict
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reverse_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '29', '47']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'new_dict'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'add_to_dict_val_set'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '21', '26']}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'new_dict'}, {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '29', 'type': 'for_statement', 'children': ['30', '31', '32']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'new_dict'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '38']}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'new_dict'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '44']}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'new_dict'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '46', 'type': 'False', 'children': []}, {'id': '47', 'type': 'return_statement', 'children': ['48']}
def reverse_dict(dict_obj): new_dict = {} for key in dict_obj: add_to_dict_val_set(dict_obj=new_dict, key=dict_obj[key], val=key) for key in new_dict: new_dict[key] = sorted(new_dict[key], reverse=False) return new_dict
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'flatten_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'separator'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'flatten_lists'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '19', '23', '55', '115', '120']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'reducer'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_get_key_reducer'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'separator'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'flat'}; {'id': '22', 'type': 'dictionary', 'children': []}, {'id': '23', 'type': 'function_definition', 'children': ['24', '25', '29']}; {'id': '24', 'type': 'function_name', 'children': [], 'value': '_flatten_key_val'}, {'id': '25', 'type': 'parameters', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '29', 'type': 'block', 'children': ['30', '38']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'flat_key'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'reducer'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '38', 'type': 'try_statement', 'children': ['39', '46']}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_flatten'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'flat_key'}; {'id': '46', 'type': 'except_clause', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '54']}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'flat'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'flat_key'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '55', 'type': 'function_definition', 'children': ['56', '57', '62']}; {'id': '56', 'type': 'function_name', 'children': [], 'value': '_flatten'}, {'id': '57', 'type': 'parameters', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '59', 'type': 'default_parameter', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'try_statement', 'children': ['64', '82']}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'for_statement', 'children': ['66', '69', '74']}; {'id': '66', 'type': 'pattern_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': '_flatten_key_val'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80', '81']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '82', 'type': 'except_clause', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '84', 'type': 'block', 'children': ['85', '96']}, {'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': 'd'}; {'id': '90', 'type': 'tuple', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'bytes'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'raise_statement', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '96', 'type': 'for_statement', 'children': ['97', '100', '104']}, {'id': '97', 'type': 'pattern_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '_flatten_key_val'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '113', '114']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': '_flatten'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}; {'id': '120', 'type': 'return_statement', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'flat'}
def flatten_dict(dict_obj, separator='.', flatten_lists=False): reducer = _get_key_reducer(separator) flat = {} def _flatten_key_val(key, val, parent): flat_key = reducer(parent, key) try: _flatten(val, flat_key) except TypeError: flat[flat_key] = val def _flatten(d, parent=None): try: for key, val in d.items(): _flatten_key_val(key, val, parent) except AttributeError: if isinstance(d, (str, bytes)): raise TypeError for i, value in enumerate(d): _flatten_key_val(str(i), value, parent) _flatten(dict_obj) return flat
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'key_value_nested_generator'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '10', '15']}, {'id': '7', 'type': 'pattern_list', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '14', 'type': 'argument_list', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '22', '37']}, {'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': 'value'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'for_statement', 'children': ['24', '27', '31']}; {'id': '24', 'type': 'pattern_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key_value_nested_generator'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'yield', 'children': ['34']}; {'id': '34', 'type': 'expression_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '37', 'type': 'else_clause', 'children': ['38']}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'yield', 'children': ['41']}, {'id': '41', 'type': 'expression_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'value'}
def key_value_nested_generator(dict_obj): for key, value in dict_obj.items(): if isinstance(value, dict): for key, value in key_value_nested_generator(value): yield key, value else: yield key, value
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'key_tuple_value_nested_generator'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '10', '15']}, {'id': '7', 'type': 'pattern_list', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dict_obj'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '14', 'type': 'argument_list', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '22', '43']}, {'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': 'value'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'for_statement', 'children': ['24', '27', '31']}; {'id': '24', 'type': 'pattern_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'nested_key'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key_tuple_value_nested_generator'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'yield', 'children': ['34']}; {'id': '34', 'type': 'expression_list', 'children': ['35', '42']}, {'id': '35', 'type': 'binary_operator', 'children': ['36', '41'], 'value': '+'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'list', 'children': ['40'], 'value': '[key]'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'nested_key'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '43', 'type': 'else_clause', 'children': ['44']}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'yield', 'children': ['47']}, {'id': '47', 'type': 'expression_list', 'children': ['48', '53']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'list', 'children': ['52'], 'value': '[key]'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'value'}
def key_tuple_value_nested_generator(dict_obj): for key, value in dict_obj.items(): if isinstance(value, dict): for nested_key, value in key_tuple_value_nested_generator(value): yield tuple([key]) + nested_key, value else: yield tuple([key]), value
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'release_lock'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'VERBOSE'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'raiseError'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'RAISE_ERROR'}, {'id': '11', 'type': 'block', 'children': ['12', '241', '333']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '24', '33']}, {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '20']}, {'id': '15', 'type': 'attribute', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'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': '__lockPath'}; {'id': '24', 'type': 'block', 'children': ['25', '29']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'released'}; {'id': '28', 'type': 'True', 'children': []}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'else_clause', 'children': ['34']}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'try_statement', 'children': ['36', '59', '101']}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'with_statement', 'children': ['38', '50']}; {'id': '38', 'type': 'with_clause', 'children': ['39']}, {'id': '39', 'type': 'with_item', 'children': ['40']}; {'id': '40', 'type': 'as_pattern', 'children': ['41', '48']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '__lockPath'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '48', 'type': 'as_pattern_target', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'fd'}; {'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': 'lock'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'fd'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'readlines'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'except_clause', 'children': ['60', '64']}; {'id': '60', 'type': 'as_pattern', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '62', 'type': 'as_pattern_target', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '64', 'type': 'block', 'children': ['65', '81', '85', '96']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '%'}; {'id': '72', 'type': 'string', 'children': [], 'value': '"Unable to read release lock file \'%s\' (%s)"'}, {'id': '73', 'type': 'tuple', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': '__lockPath'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'released'}; {'id': '84', 'type': 'False', 'children': []}, {'id': '85', 'type': 'if_statement', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'raiseError'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'raise_statement', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'code'}, {'id': '101', 'type': 'else_clause', 'children': ['102']}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'if_statement', 'children': ['104', '109', '118', '231']}; {'id': '104', 'type': 'not_operator', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'lock'}, {'id': '109', 'type': 'block', 'children': ['110', '114']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'code'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'released'}, {'id': '117', 'type': 'True', 'children': []}; {'id': '118', 'type': 'elif_clause', 'children': ['119', '134']}, {'id': '119', 'type': 'comparison_operator', 'children': ['120', '127'], 'value': '=='}; {'id': '120', 'type': 'call', 'children': ['121', '126']}, {'id': '121', 'type': 'attribute', 'children': ['122', '125']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '126', 'type': 'argument_list', 'children': []}, {'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': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': '__lockPass'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'try_statement', 'children': ['136', '179', '221']}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'with_statement', 'children': ['138', '150']}; {'id': '138', 'type': 'with_clause', 'children': ['139']}, {'id': '139', 'type': 'with_item', 'children': ['140']}; {'id': '140', 'type': 'as_pattern', 'children': ['141', '148']}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '__lockPath'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '148', 'type': 'as_pattern_target', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '150', 'type': 'block', 'children': ['151', '162', '168']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'string', 'children': [], 'value': "''"}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '161', 'type': 'argument_list', 'children': []}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'flush'}, {'id': '167', 'type': 'argument_list', 'children': []}; {'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': 'os'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'fsync'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'fileno'}; {'id': '178', 'type': 'argument_list', 'children': []}, {'id': '179', 'type': 'except_clause', 'children': ['180', '184']}; {'id': '180', 'type': 'as_pattern', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '182', 'type': 'as_pattern_target', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '184', 'type': 'block', 'children': ['185', '189', '205', '216']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'released'}; {'id': '188', 'type': 'False', 'children': []}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '%'}; {'id': '196', 'type': 'string', 'children': [], 'value': '"Unable to write release lock file \'%s\' (%s)"'}, {'id': '197', 'type': 'tuple', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': '__lockPath'}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '205', 'type': 'if_statement', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '207', 'type': 'block', 'children': ['208']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '216', 'type': 'if_statement', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'raiseError'}; {'id': '218', 'type': 'block', 'children': ['219']}, {'id': '219', 'type': 'raise_statement', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'code'}, {'id': '221', 'type': 'else_clause', 'children': ['222']}; {'id': '222', 'type': 'block', 'children': ['223', '227']}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'released'}; {'id': '226', 'type': 'True', 'children': []}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '230', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '231', 'type': 'else_clause', 'children': ['232']}; {'id': '232', 'type': 'block', 'children': ['233', '237']}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'released'}; {'id': '240', 'type': 'False', 'children': []}, {'id': '241', 'type': 'if_statement', 'children': ['242', '249']}; {'id': '242', 'type': 'boolean_operator', 'children': ['243', '244'], 'value': 'and'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'released'}; {'id': '244', 'type': 'comparison_operator', 'children': ['245', '248'], 'value': 'is'}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': '__fd'}; {'id': '248', 'type': 'None', 'children': []}, {'id': '249', 'type': 'block', 'children': ['250']}; {'id': '250', 'type': 'try_statement', 'children': ['251', '289', '327']}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'if_statement', 'children': ['253', '259']}, {'id': '253', 'type': 'not_operator', 'children': ['254']}; {'id': '254', 'type': 'attribute', 'children': ['255', '258']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': '__fd'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'closed'}, {'id': '259', 'type': 'block', 'children': ['260', '268', '281']}; {'id': '260', 'type': 'expression_statement', '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': 'self'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': '__fd'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'flush'}, {'id': '267', 'type': 'argument_list', 'children': []}; {'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': 'os'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'fsync'}, {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'call', 'children': ['275', '280']}, {'id': '275', 'type': 'attribute', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': '__fd'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'fileno'}; {'id': '280', 'type': 'argument_list', 'children': []}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '288']}, {'id': '283', 'type': 'attribute', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': '__fd'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '288', 'type': 'argument_list', 'children': []}, {'id': '289', 'type': 'except_clause', 'children': ['290', '294']}; {'id': '290', 'type': 'as_pattern', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '292', 'type': 'as_pattern_target', 'children': ['293']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '294', 'type': 'block', 'children': ['295', '311', '322']}, {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '298', 'type': 'call', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'binary_operator', 'children': ['302', '303'], 'value': '%'}; {'id': '302', 'type': 'string', 'children': [], 'value': '"Unable to close file descriptor of locked file \'%s\' (%s)"'}, {'id': '303', 'type': 'tuple', 'children': ['304', '307']}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': '__filePath'}, {'id': '307', 'type': 'call', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '311', 'type': 'if_statement', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '313', 'type': 'block', 'children': ['314']}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '317', 'type': 'argument_list', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '322', 'type': 'if_statement', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'raiseError'}; {'id': '324', 'type': 'block', 'children': ['325']}, {'id': '325', 'type': 'raise_statement', 'children': ['326']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'code'}, {'id': '327', 'type': 'else_clause', 'children': ['328']}; {'id': '328', 'type': 'block', 'children': ['329']}, {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'assignment', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '332', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '333', 'type': 'return_statement', 'children': ['334']}; {'id': '334', 'type': 'expression_list', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'released'}
def release_lock(self, verbose=VERBOSE, raiseError=RAISE_ERROR): if not os.path.isfile(self.__lockPath): released = True code = 0 else: try: with open(self.__lockPath, 'rb') as fd: lock = fd.readlines() except Exception as err: code = Exception( "Unable to read release lock file '%s' (%s)"%(self.__lockPath,str(err)) ) released = False if verbose: print(str(code)) if raiseError: raise code else: if not len(lock): code = 1 released = True elif lock[0].rstrip() == self.__lockPass.encode(): try: with open(self.__lockPath, 'wb') as f: f.write( ''.encode() ) f.flush() os.fsync(f.fileno()) except Exception as err: released = False code = Exception( "Unable to write release lock file '%s' (%s)"%(self.__lockPath,str(err)) ) if verbose: print(str(code)) if raiseError: raise code else: released = True code = 2 else: code = 4 released = False if released and self.__fd is not None: try: if not self.__fd.closed: self.__fd.flush() os.fsync(self.__fd.fileno()) self.__fd.close() except Exception as err: code = Exception( "Unable to close file descriptor of locked file '%s' (%s)"%(self.__filePath,str(err)) ) if verbose: print(str(code)) if raiseError: raise code else: code = 3 return released, code
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'guess_codec'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '7', 'type': 'string', 'children': [], 'value': '"strict"'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'require_char'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '19', '26', '34', '40', '216']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'gedcom_char_to_codec'}, {'id': '15', 'type': 'dictionary', 'children': ['16']}; {'id': '16', 'type': 'pair', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'ansel'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'gedcom'"}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'bom_codec'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'check_bom'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bom_size'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tell'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'codec'}, {'id': '37', 'type': 'boolean_operator', 'children': ['38', '39'], 'value': 'or'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'bom_codec'}, {'id': '39', 'type': 'string', 'children': [], 'value': "'gedcom'"}; {'id': '40', 'type': 'while_statement', 'children': ['41', '42']}, {'id': '41', 'type': 'True', 'children': []}; {'id': '42', 'type': 'block', 'children': ['43', '51', '60', '73', '81']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'readline'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'if_statement', 'children': ['52', '54']}; {'id': '52', 'type': 'not_operator', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'raise_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'string', 'children': [], 'value': '"Unexpected EOF while reading GEDCOM header"'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '63', 'type': 'call', 'children': ['64', '71']}; {'id': '64', 'type': 'attribute', 'children': ['65', '70']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'lstrip'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'rstrip'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'string', 'children': [], 'value': 'b"\\r\\n"'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'words'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'if_statement', 'children': ['82', '100', '112']}; {'id': '82', 'type': 'boolean_operator', 'children': ['83', '95'], 'value': 'and'}, {'id': '83', 'type': 'boolean_operator', 'children': ['84', '90'], 'value': 'and'}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '89'], 'value': '>='}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': '=='}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '94', 'type': 'string', 'children': [], 'value': 'b"0"'}, {'id': '95', 'type': 'comparison_operator', 'children': ['96', '99'], 'value': '!='}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'words'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '99', 'type': 'string', 'children': [], 'value': 'b"HEAD"'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'if_statement', 'children': ['102', '103', '109']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'require_char'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'raise_statement', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'CodecError'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': '"GEDCOM header does not have CHAR record"'}, {'id': '109', 'type': 'else_clause', 'children': ['110']}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'break_statement', 'children': []}; {'id': '112', 'type': 'elif_clause', 'children': ['113', '131']}, {'id': '113', 'type': 'boolean_operator', 'children': ['114', '126'], 'value': 'and'}; {'id': '114', 'type': 'boolean_operator', 'children': ['115', '121'], 'value': 'and'}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '120'], 'value': '>='}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'words'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '125'], 'value': '=='}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'words'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'string', 'children': [], 'value': 'b"1"'}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '=='}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '130', 'type': 'string', 'children': [], 'value': 'b"CHAR"'}, {'id': '131', 'type': 'block', 'children': ['132', '188', '215']}; {'id': '132', 'type': 'try_statement', 'children': ['133', '175']}, {'id': '133', 'type': 'block', 'children': ['134', '146', '164']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '137', 'type': 'call', 'children': ['138', '143']}; {'id': '138', 'type': 'attribute', 'children': ['139', '142']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'words'}, {'id': '141', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'codec'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'gedcom_char_to_codec'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '153', 'type': 'argument_list', 'children': ['154', '159']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '158', 'type': 'argument_list', 'children': []}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '163', 'type': 'argument_list', 'children': []}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'new_codec'}, {'id': '167', 'type': 'attribute', 'children': ['168', '174']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'codecs'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'lookup'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '175', 'type': 'except_clause', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'LookupError'}, {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'raise_statement', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'CodecError'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'string', 'children': [], 'value': '"Unknown codec name {0}"'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '192', '197']}, {'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'is'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'bom_codec'}, {'id': '191', 'type': 'None', 'children': []}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'codec'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'new_codec'}, {'id': '197', 'type': 'elif_clause', 'children': ['198', '201']}; {'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': '!='}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'new_codec'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'bom_codec'}, {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'raise_statement', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'CodecError'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '212']}, {'id': '207', 'type': 'attribute', 'children': ['208', '211']}; {'id': '208', 'type': 'concatenated_string', 'children': ['209', '210']}, {'id': '209', 'type': 'string', 'children': [], 'value': '"CHAR codec {0} is different from BOM "'}; {'id': '210', 'type': 'string', 'children': [], 'value': '"codec {1}"'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '212', 'type': 'argument_list', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'new_codec'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'bom_codec'}, {'id': '215', 'type': 'break_statement', 'children': []}; {'id': '216', 'type': 'return_statement', 'children': ['217']}, {'id': '217', 'type': 'expression_list', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'codec'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'bom_size'}
def guess_codec(file, errors="strict", require_char=False): gedcom_char_to_codec = { 'ansel': 'gedcom', } bom_codec = check_bom(file) bom_size = file.tell() codec = bom_codec or 'gedcom' while True: line = file.readline() if not line: raise IOError("Unexpected EOF while reading GEDCOM header") line = line.lstrip().rstrip(b"\r\n") words = line.split() if len(words) >= 2 and words[0] == b"0" and words[1] != b"HEAD": if require_char: raise CodecError("GEDCOM header does not have CHAR record") else: break elif len(words) >= 3 and words[0] == b"1" and words[1] == b"CHAR": try: encoding = words[2].decode(codec, errors) encoding = gedcom_char_to_codec.get(encoding.lower(), encoding.lower()) new_codec = codecs.lookup(encoding).name except LookupError: raise CodecError("Unknown codec name {0}".format(encoding)) if bom_codec is None: codec = new_codec elif new_codec != bom_codec: raise CodecError("CHAR codec {0} is different from BOM " "codec {1}".format(new_codec, bom_codec)) break return codec, bom_size
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_record'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '19', '23', '161', '214']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_log'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}, {'id': '13', 'type': 'string', 'children': [], 'value': '"in read_record(%s)"'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'reclevel'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '31']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'gline'}, {'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': 'gedcom_lines'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '31', 'type': 'block', 'children': ['32', '40', '46', '61', '106', '114', '132', '145', '155']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': '_log'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '" read_record, gline: %s"'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'gline'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'gline'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50', '55']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'reclevel'}, {'id': '49', 'type': 'None', 'children': []}; {'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': 'reclevel'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '55', 'type': 'elif_clause', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '<='}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'reclevel'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'break_statement', 'children': []}, {'id': '61', 'type': 'for_statement', 'children': ['62', '63', '71']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '68', 'type': 'slice', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '70', 'type': 'colon', 'children': []}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'if_statement', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '74', 'type': 'block', 'children': ['75', '100']}, {'id': '75', 'type': 'if_statement', 'children': ['76', '81']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '80'], 'value': 'is'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '80', 'type': 'None', 'children': []}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '87', 'type': 'call', 'children': ['88', '93']}; {'id': '88', 'type': 'attribute', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_encoding'}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': '_errors'}; {'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': 'rec'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'freeze'}, {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'delete_statement', 'children': ['107']}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '109', 'type': 'slice', 'children': ['110', '113']}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '112'], 'value': '+'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '113', 'type': 'colon', 'children': []}; {'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': 'stack'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '123'], 'value': '*'}, {'id': '121', 'type': 'list', 'children': ['122'], 'value': '[None]'}; {'id': '122', 'type': 'None', 'children': []}, {'id': '123', 'type': 'parenthesized_expression', 'children': ['124'], 'value': '()'}; {'id': '124', 'type': 'binary_operator', 'children': ['125', '128'], 'value': '-'}, {'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '+'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '127', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '135', 'type': 'conditional_expression', 'children': ['136', '141', '144'], 'value': 'if'}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '-'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': '>'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '144', 'type': 'None', 'children': []}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'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': '_make_record'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'gline'}, {'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': 'stack'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '161', 'type': 'for_statement', 'children': ['162', '163', '171']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '168', 'type': 'slice', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'reclevel'}; {'id': '170', 'type': 'colon', 'children': []}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'if_statement', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '174', 'type': 'block', 'children': ['175', '200', '206']}, {'id': '175', 'type': 'if_statement', 'children': ['176', '181']}; {'id': '176', 'type': 'comparison_operator', 'children': ['177', '180'], 'value': 'is'}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '180', 'type': 'None', 'children': []}, {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '187', 'type': 'call', 'children': ['188', '193']}; {'id': '188', 'type': 'attribute', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '193', 'type': 'argument_list', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '_encoding'}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': '_errors'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'freeze'}, {'id': '205', 'type': 'argument_list', 'children': []}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': '_log'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '211', 'type': 'argument_list', 'children': ['212', '213']}; {'id': '212', 'type': 'string', 'children': [], 'value': '" read_record, rec: %s"'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '214', 'type': 'return_statement', 'children': ['215']}, {'id': '215', 'type': 'conditional_expression', 'children': ['216', '219', '220'], 'value': 'if'}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'reclevel'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'stack'}
def read_record(self, offset): _log.debug("in read_record(%s)", offset) stack = [] reclevel = None for gline in self.gedcom_lines(offset): _log.debug(" read_record, gline: %s", gline) level = gline.level if reclevel is None: reclevel = level elif level <= reclevel: break for rec in reversed(stack[level:]): if rec: if rec.value is not None: rec.value = rec.value.decode(self._encoding, self._errors) rec.freeze() del stack[level + 1:] stack.extend([None] * (level + 1 - len(stack))) parent = stack[level - 1] if level > 0 else None rec = self._make_record(parent, gline) stack[level] = rec for rec in reversed(stack[reclevel:]): if rec: if rec.value is not None: rec.value = rec.value.decode(self._encoding, self._errors) rec.freeze() _log.debug(" read_record, rec: %s", rec) return stack[reclevel] if stack else None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_make_record'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'gline'}, {'id': '7', 'type': 'block', 'children': ['8', '68', '74', '99', '141', '153']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '18']}, {'id': '9', 'type': 'boolean_operator', 'children': ['10', '11'], 'value': 'and'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '15'], 'value': 'in'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'gline'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '15', 'type': 'tuple', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"CONT"'}, {'id': '17', 'type': 'string', 'children': [], 'value': '"CONC"'}; {'id': '18', 'type': 'block', 'children': ['19', '66']}, {'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': 'parent'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '24', 'type': 'string', 'children': [], 'value': '"BLOB"'}, {'id': '25', 'type': 'block', 'children': ['26', '32', '48']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'gline'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '38']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': '=='}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'gline'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '37', 'type': 'string', 'children': [], 'value': '"CONT"'}; {'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': 'value'}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '+'}, {'id': '43', 'type': 'string', 'children': [], 'value': 'b"\\n"'}; {'id': '44', 'type': 'parenthesized_expression', 'children': ['45'], 'value': '()'}, {'id': '45', 'type': 'boolean_operator', 'children': ['46', '47'], 'value': 'or'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '47', 'type': 'string', 'children': [], 'value': 'b""'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53']}, {'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': 'parent'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '65'], 'value': '+'}, {'id': '59', 'type': 'parenthesized_expression', 'children': ['60'], 'value': '()'}; {'id': '60', 'type': 'boolean_operator', 'children': ['61', '64'], 'value': 'or'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '64', 'type': 'string', 'children': [], 'value': 'b""'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'dialect'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'DIALECT_DEFAULT'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '92']}, {'id': '75', 'type': 'boolean_operator', 'children': ['76', '89'], 'value': 'and'}; {'id': '76', 'type': 'not_operator', 'children': ['77']}, {'id': '77', 'type': 'parenthesized_expression', 'children': ['78'], 'value': '()'}; {'id': '78', 'type': 'boolean_operator', 'children': ['79', '84'], 'value': 'and'}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '83'], 'value': '=='}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'gline'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '88'], 'value': '=='}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'gline'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"HEAD"'}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': '_header'}; {'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': 'dialect'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'dialect'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'make_record'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '112', '117', '122', '127', '130', '135', '138']}, {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'gline'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'xref_id'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'gline'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'xref_id'}, {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'gline'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'gline'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'sub_records'}, {'id': '129', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'gline'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'dialect'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '141', 'type': 'if_statement', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '151']}; {'id': '146', 'type': 'attribute', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'sub_records'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '153', 'type': 'return_statement', 'children': ['154']}
def _make_record(self, parent, gline): if parent and gline.tag in ("CONT", "CONC"): if parent.tag != "BLOB": value = gline.value if gline.tag == "CONT": value = b"\n" + (value or b"") if value is not None: parent.value = (parent.value or b"") + value return None dialect = model.DIALECT_DEFAULT if not (gline.level == 0 and gline.tag == "HEAD") and self._header: dialect = self.dialect rec = model.make_record(level=gline.level, xref_id=gline.xref_id, tag=gline.tag, value=gline.value, sub_records=[], offset=gline.offset, dialect=dialect, parser=self) if parent: parent.sub_records.append(rec) return rec
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'gvid'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '25', '34', '57', '143', '182', '193', '210', '218', '224', '245', '264', '274']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': '=='}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'gvid'}, {'id': '13', 'type': 'string', 'children': [], 'value': "'invalid'"}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '23']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'get_class'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'null'"}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '31']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'gvid'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'if_statement', 'children': ['35', '43']}, {'id': '35', 'type': 'not_operator', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'gvid'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'raise_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"Can\'t parse; not a string. Got a \'{}\' "'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'gvid'}, {'id': '57', 'type': 'try_statement', 'children': ['58', '108']}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'if_statement', 'children': ['60', '64', '100']}; {'id': '60', 'type': 'not_operator', 'children': ['61']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sl'}; {'id': '64', 'type': 'block', 'children': ['65', '86']}, {'id': '65', 'type': 'if_statement', 'children': ['66', '69', '76']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'PY3'}, {'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': 'fn'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '76', 'type': 'else_clause', 'children': ['77']}, {'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': 'fn'}, {'id': '81', 'type': 'attribute', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': '__func__'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sl'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'gvid'}; {'id': '94', 'type': 'slice', 'children': ['95', '96', '97']}, {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'colon', 'children': []}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sl_width'}; {'id': '100', 'type': 'else_clause', 'children': ['101']}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'sl'}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sl'}; {'id': '108', 'type': 'except_clause', 'children': ['109', '113']}, {'id': '109', 'type': 'as_pattern', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '111', 'type': 'as_pattern_target', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'if_statement', 'children': ['115', '116', '131']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'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': 'ValueError'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'string', 'children': [], 'value': '"Failed to parse gvid \'{}\': {}"'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'gvid'}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '131', 'type': 'else_clause', 'children': ['132']}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'return_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '141']}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'get_class'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'null'"}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '143', 'type': 'try_statement', 'children': ['144', '153']}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '148', 'type': 'subscript', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'sl_map'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'sl'}, {'id': '153', 'type': 'except_clause', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'if_statement', 'children': ['157', '158', '170']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'raise_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'string', 'children': [], 'value': '"Failed to parse gvid \'{}\': Unknown summary level \'{}\' "'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '167', 'type': 'argument_list', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'gvid'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'sl'}; {'id': '170', 'type': 'else_clause', 'children': ['171']}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'return_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '180']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'get_class'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'string', 'children': [], 'value': "'null'"}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'm'}, {'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': 'cls'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'regex'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'gvid'}, {'id': '193', 'type': 'if_statement', 'children': ['194', '196']}; {'id': '194', 'type': 'not_operator', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'm'}; {'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': 'ValueError'}; {'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': '"Failed to match \'{}\' to \'{}\' "'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '205', 'type': 'argument_list', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'gvid'}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'regex_str'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'groupdict'}, {'id': '217', 'type': 'argument_list', 'children': []}; {'id': '218', 'type': 'if_statement', 'children': ['219', '221']}, {'id': '219', 'type': 'not_operator', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '221', 'type': 'block', 'children': ['222']}; {'id': '222', 'type': 'return_statement', 'children': ['223']}, {'id': '223', 'type': 'None', 'children': []}; {'id': '224', 'type': 'if_statement', 'children': ['225', '228', '235']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'PY3'}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '235', 'type': 'else_clause', 'children': ['236']}; {'id': '236', 'type': 'block', 'children': ['237']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '240', 'type': 'attribute', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': '__func__'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '248', 'type': 'dictionary_comprehension', 'children': ['249', '255']}, {'id': '249', 'type': 'pair', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '255', 'type': 'for_in_clause', 'children': ['256', '259']}; {'id': '256', 'type': 'pattern_list', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '259', 'type': 'call', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '263', 'type': 'argument_list', 'children': []}; {'id': '264', 'type': 'try_statement', 'children': ['265', '270']}, {'id': '265', 'type': 'block', 'children': ['266']}; {'id': '266', 'type': 'delete_statement', 'children': ['267']}, {'id': '267', 'type': 'subscript', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '269', 'type': 'string', 'children': [], 'value': "'sl'"}; {'id': '270', 'type': 'except_clause', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'pass_statement', 'children': []}; {'id': '274', 'type': 'return_statement', 'children': ['275']}, {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'dictionary_splat', 'children': ['279']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'd'}
def parse(cls, gvid, exception=True): if gvid == 'invalid': return cls.get_class('null')(0) if not bool(gvid): return None if not isinstance(gvid, six.string_types): raise TypeError("Can't parse; not a string. Got a '{}' ".format(type(gvid))) try: if not cls.sl: if six.PY3: fn = cls.decode else: fn = cls.decode.__func__ sl = fn(gvid[0:cls.sl_width]) else: sl = cls.sl except ValueError as e: if exception: raise ValueError("Failed to parse gvid '{}': {}".format(gvid, str(e))) else: return cls.get_class('null')(0) try: cls = cls.sl_map[sl] except KeyError: if exception: raise ValueError("Failed to parse gvid '{}': Unknown summary level '{}' ".format(gvid, sl)) else: return cls.get_class('null')(0) m = cls.regex.match(gvid) if not m: raise ValueError("Failed to match '{}' to '{}' ".format(gvid, cls.regex_str)) d = m.groupdict() if not d: return None if six.PY3: fn = cls.decode else: fn = cls.decode.__func__ d = {k: fn(v) for k, v in d.items()} try: del d['sl'] except KeyError: pass return cls(**d)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_pastdate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'string'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '19', '29', '53', '73', '116', '172', '178']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '16']}; {'id': '10', 'type': 'boolean_operator', 'children': ['11', '13'], 'value': 'and'}, {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'string'}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'today'}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'today'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'try_statement', 'children': ['30', '45']}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}, {'id': '43', 'type': 'string', 'children': [], 'value': "'\\D+'"}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'string'}, {'id': '45', 'type': 'except_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'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': 'InvalidInputError'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': '"invalid date; use format: DD [MM [YYYY]]"'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '67']}; {'id': '54', 'type': 'boolean_operator', 'children': ['55', '61'], 'value': 'or'}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '60'], 'value': '<'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '66'], 'value': '>'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '3'}, {'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': 'InvalidInputError'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'string', 'children': [], 'value': '"invalid date; use format: DD [MM [YYYY]]"'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '80']}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '79'], 'value': '=='}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '80', 'type': 'block', 'children': ['81', '103']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'conditional_expression', 'children': ['88', '93', '100'], 'value': 'if'}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '92'], 'value': '-'}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'today'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '97'], 'value': '>'}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'today'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'today'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'month'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '109']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '<'}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '115']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '115', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '116', 'type': 'if_statement', 'children': ['117', '123']}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '122'], 'value': '=='}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'if_statement', 'children': ['125', '149', '161']}, {'id': '125', 'type': 'boolean_operator', 'children': ['126', '133', '134'], 'value': 'or'}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '>'}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'today'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'month'}, {'id': '133', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '134', 'type': 'boolean_operator', 'children': ['135', '142'], 'value': 'and'}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '139'], 'value': '=='}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'today'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '146'], 'value': '>'}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'today'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'day'}, {'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': 'parts'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'binary_operator', 'children': ['157', '160'], 'value': '-'}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'today'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '160', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '161', 'type': 'else_clause', 'children': ['162']}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'today'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'year'}; {'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': 'parts'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'try_statement', 'children': ['179', '202']}, {'id': '179', 'type': 'block', 'children': ['180', '190', '200']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'list_splat', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '190', 'type': 'if_statement', 'children': ['191', '194']}, {'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': '>'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'today'}; {'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': 'InvalidInputError'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'string', 'children': [], 'value': '"cannot choose a date in the future"'}; {'id': '200', 'type': 'return_statement', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '202', 'type': 'except_clause', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '204', 'type': 'block', 'children': ['205', '207']}, {'id': '205', 'type': 'print_statement', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '207', 'type': 'raise_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'InvalidInputError'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'string', 'children': [], 'value': '"invalid date; use format: DD [MM [YYYY]]"'}
def filter_pastdate(string, default=None): if not string and default is not None: return default today = datetime.date.today() try: parts = map(int, re.split('\D+', string)) except ValueError: raise InvalidInputError("invalid date; use format: DD [MM [YYYY]]") if len(parts) < 1 or len(parts) > 3: raise InvalidInputError("invalid date; use format: DD [MM [YYYY]]") if len(parts) == 1: parts.append(today.month - 1 if parts[0] > today.day else today.month) if parts[1] < 1: parts[1] = 12 if len(parts) == 2: if parts[1] > today.month \ or parts[1] == today.month and parts[0] > today.day: parts.append(today.year - 1) else: parts.append(today.year) parts.reverse() try: date = datetime.date(*parts) if date > today: raise InvalidInputError("cannot choose a date in the future") return date except ValueError: print parts raise InvalidInputError("invalid date; use format: DD [MM [YYYY]]")
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_rooms'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'lid'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '17', '78', '97', '109', '119', '129', '145', '154', '162', '176', '194', '209', '446']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'range_str'}; {'id': '16', 'type': 'string', 'children': [], 'value': '"availability"'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '19', '72']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '19', 'type': 'block', 'children': ['20', '52', '58']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'start_datetime'}, {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'combine'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '43']}; {'id': '30', 'type': 'call', 'children': ['31', '42']}, {'id': '31', 'type': 'attribute', 'children': ['32', '41']}; {'id': '32', 'type': 'call', 'children': ['33', '38']}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'strptime'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '40', 'type': 'string', 'children': [], 'value': '"%Y-%m-%d"'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'call', 'children': ['44', '51']}; {'id': '44', 'type': 'attribute', 'children': ['45', '50']}, {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'augmented_assignment', 'children': ['54', '55'], 'value': '+='}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'range_str'}, {'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '+'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"="'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '58', 'type': 'if_statement', 'children': ['59', '65']}, {'id': '59', 'type': 'boolean_operator', 'children': ['60', '61'], 'value': 'and'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '61', 'type': 'not_operator', 'children': ['62']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '=='}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'augmented_assignment', 'children': ['68', '69'], 'value': '+='}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'range_str'}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '+'}; {'id': '70', 'type': 'string', 'children': [], 'value': '","'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '72', 'type': 'else_clause', 'children': ['73']}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'start_datetime'}, {'id': '77', 'type': 'None', 'children': []}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '81', 'type': 'call', 'children': ['82', '96']}; {'id': '82', 'type': 'attribute', 'children': ['83', '95']}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': '_request'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'string', 'children': [], 'value': '"GET"'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'string', 'children': [], 'value': '"/1.1/space/categories/{}"'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'lid'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '96', 'type': 'argument_list', 'children': []}, {'id': '97', 'type': 'if_statement', 'children': ['98', '101']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'in'}, {'id': '99', 'type': 'string', 'children': [], 'value': '"error"'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'raise_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'APIError'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '108', 'type': 'string', 'children': [], 'value': '"error"'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '112', 'type': 'dictionary', 'children': ['113', '116']}, {'id': '113', 'type': 'pair', 'children': ['114', '115']}; {'id': '114', 'type': 'string', 'children': [], 'value': '"id"'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'lid'}; {'id': '116', 'type': 'pair', 'children': ['117', '118']}, {'id': '117', 'type': 'string', 'children': [], 'value': '"categories"'}; {'id': '118', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '126']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '125'], 'value': '<'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'return_statement', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '129', 'type': 'if_statement', 'children': ['130', '135']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'in'}, {'id': '131', 'type': 'string', 'children': [], 'value': '"error"'}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'raise_statement', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'APIError'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'subscript', 'children': ['141', '144']}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '144', 'type': 'string', 'children': [], 'value': '"error"'}, {'id': '145', 'type': 'if_statement', 'children': ['146', '151']}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': 'not'}, {'id': '147', 'type': 'string', 'children': [], 'value': '"categories"'}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'return_statement', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'categories'}, {'id': '157', 'type': 'subscript', 'children': ['158', '161']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '160', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '161', 'type': 'string', 'children': [], 'value': '"categories"'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'id_to_category'}, {'id': '165', 'type': 'dictionary_comprehension', 'children': ['166', '173']}; {'id': '166', 'type': 'pair', 'children': ['167', '170']}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '169', 'type': 'string', 'children': [], 'value': '"cid"'}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '172', 'type': 'string', 'children': [], 'value': '"name"'}, {'id': '173', 'type': 'for_in_clause', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'categories'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'categories'}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'string', 'children': [], 'value': '","'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'list_comprehension', 'children': ['185', '191']}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '190', 'type': 'string', 'children': [], 'value': '"cid"'}, {'id': '191', 'type': 'for_in_clause', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'categories'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': '_request'}, {'id': '201', 'type': 'argument_list', 'children': ['202', '203']}; {'id': '202', 'type': 'string', 'children': [], 'value': '"GET"'}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'string', 'children': [], 'value': '"/1.1/space/category/{}"'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'categories'}, {'id': '209', 'type': 'for_statement', 'children': ['210', '211', '216']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'category'}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '215', 'type': 'argument_list', 'children': []}; {'id': '216', 'type': 'block', 'children': ['217', '236', '247', '253', '269', '285', '432']}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'cat_out'}; {'id': '220', 'type': 'dictionary', 'children': ['221', '226', '233']}, {'id': '221', 'type': 'pair', 'children': ['222', '223']}; {'id': '222', 'type': 'string', 'children': [], 'value': '"cid"'}, {'id': '223', 'type': 'subscript', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'category'}, {'id': '225', 'type': 'string', 'children': [], 'value': '"cid"'}; {'id': '226', 'type': 'pair', 'children': ['227', '228']}, {'id': '227', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'id_to_category'}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'category'}; {'id': '232', 'type': 'string', 'children': [], 'value': '"cid"'}, {'id': '233', 'type': 'pair', 'children': ['234', '235']}; {'id': '234', 'type': 'string', 'children': [], 'value': '"rooms"'}, {'id': '235', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '236', 'type': 'if_statement', 'children': ['237', '245']}, {'id': '237', 'type': 'call', 'children': ['238', '243']}; {'id': '238', 'type': 'attribute', 'children': ['239', '242']}, {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'cat_out'}, {'id': '241', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'endswith'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'string', 'children': [], 'value': '"Equipment"'}, {'id': '245', 'type': 'block', 'children': ['246']}; {'id': '246', 'type': 'continue_statement', 'children': []}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '250', 'type': 'subscript', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'category'}; {'id': '252', 'type': 'string', 'children': [], 'value': '"items"'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'string', 'children': [], 'value': '","'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'list_comprehension', 'children': ['262', '266']}; {'id': '262', 'type': 'call', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '266', 'type': 'for_in_clause', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'assignment', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '272', 'type': 'call', 'children': ['273', '276']}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': '_request'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '278']}, {'id': '277', 'type': 'string', 'children': [], 'value': '"GET"'}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'string', 'children': [], 'value': '"/1.1/space/item/{}?{}"'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'range_str'}, {'id': '285', 'type': 'for_statement', 'children': ['286', '287', '292']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'room'}, {'id': '287', 'type': 'call', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '291', 'type': 'argument_list', 'children': []}; {'id': '292', 'type': 'block', 'children': ['293', '301', '331', '364', '373', '423']}, {'id': '293', 'type': 'if_statement', 'children': ['294', '299']}; {'id': '294', 'type': 'comparison_operator', 'children': ['295', '298'], 'value': 'in'}, {'id': '295', 'type': 'subscript', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'room'}, {'id': '297', 'type': 'string', 'children': [], 'value': '"id"'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'ROOM_BLACKLIST'}, {'id': '299', 'type': 'block', 'children': ['300']}; {'id': '300', 'type': 'continue_statement', 'children': []}, {'id': '301', 'type': 'if_statement', 'children': ['302', '309']}; {'id': '302', 'type': 'boolean_operator', 'children': ['303', '306'], 'value': 'and'}, {'id': '303', 'type': 'comparison_operator', 'children': ['304', '305'], 'value': 'in'}; {'id': '304', 'type': 'string', 'children': [], 'value': '"image"'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'room'}; {'id': '306', 'type': 'subscript', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'room'}; {'id': '308', 'type': 'string', 'children': [], 'value': '"image"'}, {'id': '309', 'type': 'block', 'children': ['310']}; {'id': '310', 'type': 'if_statement', 'children': ['311', '320']}, {'id': '311', 'type': 'not_operator', 'children': ['312']}; {'id': '312', 'type': 'call', 'children': ['313', '318']}, {'id': '313', 'type': 'attribute', 'children': ['314', '317']}; {'id': '314', 'type': 'subscript', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'room'}; {'id': '316', 'type': 'string', 'children': [], 'value': '"image"'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '318', 'type': 'argument_list', 'children': ['319']}, {'id': '319', 'type': 'string', 'children': [], 'value': '"http"'}; {'id': '320', 'type': 'block', 'children': ['321']}, {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'assignment', 'children': ['323', '326']}, {'id': '323', 'type': 'subscript', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'room'}, {'id': '325', 'type': 'string', 'children': [], 'value': '"image"'}; {'id': '326', 'type': 'binary_operator', 'children': ['327', '328'], 'value': '+'}, {'id': '327', 'type': 'string', 'children': [], 'value': '"https:"'}; {'id': '328', 'type': 'subscript', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'room'}; {'id': '330', 'type': 'string', 'children': [], 'value': '"image"'}, {'id': '331', 'type': 'if_statement', 'children': ['332', '335']}; {'id': '332', 'type': 'comparison_operator', 'children': ['333', '334'], 'value': 'in'}, {'id': '333', 'type': 'string', 'children': [], 'value': '"description"'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'room'}, {'id': '335', 'type': 'block', 'children': ['336', '348']}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'assignment', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '339', 'type': 'call', 'children': ['340', '345']}; {'id': '340', 'type': 'attribute', 'children': ['341', '344']}, {'id': '341', 'type': 'subscript', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'room'}, {'id': '343', 'type': 'string', 'children': [], 'value': '"description"'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '345', 'type': 'argument_list', 'children': ['346', '347']}; {'id': '346', 'type': 'string', 'children': [], 'value': "u'\\xa0'"}, {'id': '347', 'type': 'string', 'children': [], 'value': "u' '"}; {'id': '348', 'type': 'expression_statement', 'children': ['349']}, {'id': '349', 'type': 'assignment', 'children': ['350', '353']}; {'id': '350', 'type': 'subscript', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'room'}; {'id': '352', 'type': 'string', 'children': [], 'value': '"description"'}, {'id': '353', 'type': 'call', 'children': ['354', '363']}; {'id': '354', 'type': 'attribute', 'children': ['355', '362']}, {'id': '355', 'type': 'attribute', 'children': ['356', '361']}; {'id': '356', 'type': 'call', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'BeautifulSoup'}; {'id': '358', 'type': 'argument_list', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '360', 'type': 'string', 'children': [], 'value': '"html.parser"'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '363', 'type': 'argument_list', 'children': []}; {'id': '364', 'type': 'if_statement', 'children': ['365', '368']}, {'id': '365', 'type': 'comparison_operator', 'children': ['366', '367'], 'value': 'in'}; {'id': '366', 'type': 'string', 'children': [], 'value': '"formid"'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'room'}; {'id': '368', 'type': 'block', 'children': ['369']}, {'id': '369', 'type': 'delete_statement', 'children': ['370']}; {'id': '370', 'type': 'subscript', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'room'}; {'id': '372', 'type': 'string', 'children': [], 'value': '"formid"'}, {'id': '373', 'type': 'if_statement', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'start_datetime'}, {'id': '375', 'type': 'block', 'children': ['376', '380', '417']}; {'id': '376', 'type': 'expression_statement', 'children': ['377']}, {'id': '377', 'type': 'assignment', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'out_times'}, {'id': '379', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '380', 'type': 'for_statement', 'children': ['381', '382', '385']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '382', 'type': 'subscript', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'room'}; {'id': '384', 'type': 'string', 'children': [], 'value': '"availability"'}, {'id': '385', 'type': 'block', 'children': ['386', '405']}; {'id': '386', 'type': 'expression_statement', 'children': ['387']}, {'id': '387', 'type': 'assignment', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'parsed_start'}, {'id': '389', 'type': 'call', 'children': ['390', '395']}; {'id': '390', 'type': 'attribute', 'children': ['391', '394']}, {'id': '391', 'type': 'attribute', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'strptime'}, {'id': '395', 'type': 'argument_list', 'children': ['396', '404']}; {'id': '396', 'type': 'subscript', 'children': ['397', '400']}, {'id': '397', 'type': 'subscript', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '399', 'type': 'string', 'children': [], 'value': '"from"'}; {'id': '400', 'type': 'slice', 'children': ['401', '402']}, {'id': '401', 'type': 'colon', 'children': []}; {'id': '402', 'type': 'unary_operator', 'children': ['403'], 'value': '-'}, {'id': '403', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '404', 'type': 'string', 'children': [], 'value': '"%Y-%m-%dT%H:%M:%S"'}, {'id': '405', 'type': 'if_statement', 'children': ['406', '409']}; {'id': '406', 'type': 'comparison_operator', 'children': ['407', '408'], 'value': '>='}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'parsed_start'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'start_datetime'}, {'id': '409', 'type': 'block', 'children': ['410']}; {'id': '410', 'type': 'expression_statement', 'children': ['411']}, {'id': '411', 'type': 'call', 'children': ['412', '415']}; {'id': '412', 'type': 'attribute', 'children': ['413', '414']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'out_times'}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '415', 'type': 'argument_list', 'children': ['416']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '417', 'type': 'expression_statement', 'children': ['418']}; {'id': '418', 'type': 'assignment', 'children': ['419', '422']}, {'id': '419', 'type': 'subscript', 'children': ['420', '421']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'room'}, {'id': '421', 'type': 'string', 'children': [], 'value': '"availability"'}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'out_times'}, {'id': '423', 'type': 'expression_statement', 'children': ['424']}; {'id': '424', 'type': 'call', 'children': ['425', '430']}, {'id': '425', 'type': 'attribute', 'children': ['426', '429']}; {'id': '426', 'type': 'subscript', 'children': ['427', '428']}, {'id': '427', 'type': 'identifier', 'children': [], 'value': 'cat_out'}; {'id': '428', 'type': 'string', 'children': [], 'value': '"rooms"'}, {'id': '429', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '430', 'type': 'argument_list', 'children': ['431']}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'room'}; {'id': '432', 'type': 'if_statement', 'children': ['433', '436']}, {'id': '433', 'type': 'subscript', 'children': ['434', '435']}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'cat_out'}, {'id': '435', 'type': 'string', 'children': [], 'value': '"rooms"'}; {'id': '436', 'type': 'block', 'children': ['437']}, {'id': '437', 'type': 'expression_statement', 'children': ['438']}; {'id': '438', 'type': 'call', 'children': ['439', '444']}, {'id': '439', 'type': 'attribute', 'children': ['440', '443']}; {'id': '440', 'type': 'subscript', 'children': ['441', '442']}, {'id': '441', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '442', 'type': 'string', 'children': [], 'value': '"categories"'}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '444', 'type': 'argument_list', 'children': ['445']}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'cat_out'}; {'id': '446', 'type': 'return_statement', 'children': ['447']}, {'id': '447', 'type': 'identifier', 'children': [], 'value': 'output'}
def get_rooms(self, lid, start=None, end=None): range_str = "availability" if start: start_datetime = datetime.datetime.combine(datetime.datetime.strptime(start, "%Y-%m-%d").date(), datetime.datetime.min.time()) range_str += "=" + start if end and not start == end: range_str += "," + end else: start_datetime = None resp = self._request("GET", "/1.1/space/categories/{}".format(lid)).json() if "error" in resp: raise APIError(resp["error"]) output = {"id": lid, "categories": []} if len(resp) < 1: return output if "error" in resp[0]: raise APIError(resp[0]["error"]) if "categories" not in resp[0]: return output categories = resp[0]["categories"] id_to_category = {i["cid"]: i["name"] for i in categories} categories = ",".join([str(x["cid"]) for x in categories]) resp = self._request("GET", "/1.1/space/category/{}".format(categories)) for category in resp.json(): cat_out = {"cid": category["cid"], "name": id_to_category[category["cid"]], "rooms": []} if cat_out["name"].endswith("Equipment"): continue items = category["items"] items = ",".join([str(x) for x in items]) resp = self._request("GET", "/1.1/space/item/{}?{}".format(items, range_str)) for room in resp.json(): if room["id"] in ROOM_BLACKLIST: continue if "image" in room and room["image"]: if not room["image"].startswith("http"): room["image"] = "https:" + room["image"] if "description" in room: description = room["description"].replace(u'\xa0', u' ') room["description"] = BeautifulSoup(description, "html.parser").text.strip() if "formid" in room: del room["formid"] if start_datetime: out_times = [] for time in room["availability"]: parsed_start = datetime.datetime.strptime(time["from"][:-6], "%Y-%m-%dT%H:%M:%S") if parsed_start >= start_datetime: out_times.append(time) room["availability"] = out_times cat_out["rooms"].append(room) if cat_out["rooms"]: output["categories"].append(cat_out) return output
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reconstruct_ancestral_states'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'MPPA'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'F81'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'avg_br_len'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'num_tips'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'force_joint'}, {'id': '27', 'type': 'True', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29', '61', '77', '95', '106', '205', '221']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '39']}, {'id': '31', 'type': 'attribute', 'children': ['32', '38']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'string', 'children': [], 'value': "'pastml'"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'ACR settings for {}:\\n\\tMethod:\\t{}{}.'"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '47', 'type': 'conditional_expression', 'children': ['48', '54', '60'], 'value': 'if'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'\\n\\tModel:\\t{}'"}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '54', 'type': 'boolean_operator', 'children': ['55', '56'], 'value': 'and'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'is_ml'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}; {'id': '60', 'type': 'string', 'children': [], 'value': "''"}, {'id': '61', 'type': 'if_statement', 'children': ['62', '65']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '=='}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'COPY'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'dictionary', 'children': ['68', '71', '74']}; {'id': '68', 'type': 'pair', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'CHARACTER'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'character'}, {'id': '71', 'type': 'pair', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'STATES'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '74', 'type': 'pair', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'METHOD'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '77', 'type': 'if_statement', 'children': ['78', '80']}; {'id': '78', 'type': 'not_operator', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '86', 'type': 'generator_expression', 'children': ['87', '88']}, {'id': '87', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '88', 'type': 'for_in_clause', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'traverse'}; {'id': '94', 'type': 'argument_list', 'children': []}, {'id': '95', 'type': 'if_statement', 'children': ['96', '98']}; {'id': '96', 'type': 'not_operator', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'num_tips'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'num_tips'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '111']}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'is_ml'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '111', 'type': 'block', 'children': ['112', '139', '149', '165']}; {'id': '112', 'type': 'if_statement', 'children': ['113', '116']}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'avg_br_len'}, {'id': '115', 'type': 'None', 'children': []}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'avg_br_len'}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '124', 'type': 'generator_expression', 'children': ['125', '128', '135']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'dist'}; {'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'traverse'}; {'id': '134', 'type': 'argument_list', 'children': []}, {'id': '135', 'type': 'if_clause', 'children': ['136']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '145']}, {'id': '141', 'type': 'pattern_list', 'children': ['142', '143', '144']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'freqs'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'sf'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'kappa'}, {'id': '145', 'type': 'expression_list', 'children': ['146', '147', '148']}; {'id': '146', 'type': 'None', 'children': []}, {'id': '147', 'type': 'None', 'children': []}; {'id': '148', 'type': 'None', 'children': []}, {'id': '149', 'type': 'if_statement', 'children': ['150', '153']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': 'is'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '152', 'type': 'None', 'children': []}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '160']}; {'id': '156', 'type': 'pattern_list', 'children': ['157', '158', '159']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'freqs'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'sf'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'kappa'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': '_parse_pastml_parameters'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '165', 'type': 'return_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'ml_acr'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '172', '175', '178', '181', '184', '187', '190', '193', '196', '199', '202']}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'character'}, {'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}; {'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'avg_br_len'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'avg_br_len'}, {'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}; {'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'num_tips'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'num_tips'}, {'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'freqs'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'freqs'}; {'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'sf'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'sf'}, {'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'kappa'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'kappa'}; {'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'force_joint'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'force_joint'}, {'id': '205', 'type': 'if_statement', 'children': ['206', '210']}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'is_parsimonious'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}; {'id': '210', 'type': 'block', 'children': ['211']}, {'id': '211', 'type': 'return_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'parsimonious_acr'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '216', '217', '218', '219', '220']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'character'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'num_tips'}, {'id': '221', 'type': 'raise_statement', 'children': ['222']}; {'id': '222', 'type': 'call', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'string', 'children': [], 'value': "'Method {} is unknown, should be one of ML ({}), one of MP ({}) or {}'"}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '229', 'type': 'argument_list', 'children': ['230', '231', '237', '243']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'ML_METHODS'}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'MP_METHODS'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'COPY'}
def reconstruct_ancestral_states(tree, character, states, prediction_method=MPPA, model=F81, params=None, avg_br_len=None, num_nodes=None, num_tips=None, force_joint=True): logging.getLogger('pastml').debug('ACR settings for {}:\n\tMethod:\t{}{}.' .format(character, prediction_method, '\n\tModel:\t{}'.format(model) if model and is_ml(prediction_method) else '')) if COPY == prediction_method: return {CHARACTER: character, STATES: states, METHOD: prediction_method} if not num_nodes: num_nodes = sum(1 for _ in tree.traverse()) if not num_tips: num_tips = len(tree) if is_ml(prediction_method): if avg_br_len is None: avg_br_len = np.mean(n.dist for n in tree.traverse() if n.dist) freqs, sf, kappa = None, None, None if params is not None: freqs, sf, kappa = _parse_pastml_parameters(params, states) return ml_acr(tree=tree, character=character, prediction_method=prediction_method, model=model, states=states, avg_br_len=avg_br_len, num_nodes=num_nodes, num_tips=num_tips, freqs=freqs, sf=sf, kappa=kappa, force_joint=force_joint) if is_parsimonious(prediction_method): return parsimonious_acr(tree, character, prediction_method, states, num_nodes, num_tips) raise ValueError('Method {} is unknown, should be one of ML ({}), one of MP ({}) or {}' .format(prediction_method, ', '.join(ML_METHODS), ', '.join(MP_METHODS), COPY))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'acr'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'MPPA'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'F81'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'column2parameters'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'force_joint'}, {'id': '17', 'type': 'True', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '59', '67', '72', '82', '92', '104', '111', '134', '146', '158', '286', '341', '345', '372']}, {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '24']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}, {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '30', 'type': 'call', 'children': ['31', '36']}, {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'lambda', 'children': ['38', '40']}; {'id': '38', 'type': 'lambda_parameters', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '40', 'type': 'conditional_expression', 'children': ['41', '42', '48'], 'value': 'if'}, {'id': '41', 'type': 'string', 'children': [], 'value': "''"}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'isna'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '48', 'type': 'call', 'children': ['49', '58']}, {'id': '49', 'type': 'attribute', 'children': ['50', '57']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'ASCII'"}; {'id': '56', 'type': 'string', 'children': [], 'value': "'replace'"}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'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': 'columns'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'preannotate_tree'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'name_tree'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'collapse_zero_branches'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'features_to_be_merged'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '88']}; {'id': '84', 'type': 'pattern_list', 'children': ['85', '86', '87']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'avg_br_len'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'num_tips'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'get_tree_stats'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '102']}; {'id': '94', 'type': 'attribute', 'children': ['95', '101']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'getLogger'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'pastml'"}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'string', 'children': [], 'value': "'\\n=============ACR==============================='"}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'column2parameters'}, {'id': '107', 'type': 'conditional_expression', 'children': ['108', '109', '110'], 'value': 'if'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'column2parameters'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'column2parameters'}; {'id': '110', 'type': 'dictionary', 'children': []}, {'id': '111', 'type': 'function_definition', 'children': ['112', '113', '115']}; {'id': '112', 'type': 'function_name', 'children': [], 'value': '_work'}, {'id': '113', 'type': 'parameters', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'return_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'reconstruct_ancestral_states'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '122', '125', '128', '131']}; {'id': '120', 'type': 'list_splat', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'avg_br_len'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'avg_br_len'}, {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'num_tips'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'num_tips'}, {'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'force_joint'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'force_joint'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'prediction_methods'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'value2list'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '144', '145']}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'MPPA'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'models'}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'value2list'}, {'id': '151', 'type': 'argument_list', 'children': ['152', '156', '157']}; {'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': 'columns'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'F81'}; {'id': '158', 'type': 'function_definition', 'children': ['159', '160', '164']}, {'id': '159', 'type': 'function_name', 'children': [], 'value': 'get_states'}; {'id': '160', 'type': 'parameters', 'children': ['161', '162', '163']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '164', 'type': 'block', 'children': ['165', '190', '210', '219', '256', '263', '284']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'df_states'}; {'id': '168', 'type': 'list_comprehension', 'children': ['169', '170', '179']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '170', 'type': 'for_in_clause', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '172', 'type': 'call', 'children': ['173', '178']}, {'id': '173', 'type': 'attribute', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '178', 'type': 'argument_list', 'children': []}, {'id': '179', 'type': 'if_clause', 'children': ['180']}; {'id': '180', 'type': 'boolean_operator', 'children': ['181', '187'], 'value': 'and'}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'notnull'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': '!='}; {'id': '188', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '189', 'type': 'string', 'children': [], 'value': "''"}; {'id': '190', 'type': 'if_statement', 'children': ['191', '202']}, {'id': '191', 'type': 'boolean_operator', 'children': ['192', '197'], 'value': 'or'}; {'id': '192', 'type': 'not_operator', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'is_ml'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': 'not'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '199', 'type': 'set', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'HKY'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'JTT'}; {'id': '202', 'type': 'block', 'children': ['203']}, {'id': '203', 'type': 'return_statement', 'children': ['204']}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'df_states'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '213', 'type': 'conditional_expression', 'children': ['214', '215', '218'], 'value': 'if'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'HKY_STATES'}, {'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': '=='}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'HKY'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'JTT_STATES'}, {'id': '219', 'type': 'if_statement', 'children': ['220', '230']}; {'id': '220', 'type': 'not_operator', 'children': ['221']}, {'id': '221', 'type': 'binary_operator', 'children': ['222', '226'], 'value': '&'}; {'id': '222', 'type': 'call', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'df_states'}; {'id': '226', 'type': 'call', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '230', 'type': 'block', 'children': ['231']}, {'id': '231', 'type': 'raise_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '241']}; {'id': '236', 'type': 'attribute', 'children': ['237', '240']}, {'id': '237', 'type': 'concatenated_string', 'children': ['238', '239']}; {'id': '238', 'type': 'string', 'children': [], 'value': "'The allowed states for model {} are {}, '"}, {'id': '239', 'type': 'string', 'children': [], 'value': "'but your annotation file specifies {} as states in column {}.'"}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '243', '249', '255']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '249', 'type': 'call', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'df_states'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'state_set'}, {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '268']}, {'id': '265', 'type': 'subscript', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '268', 'type': 'call', 'children': ['269', '274']}, {'id': '269', 'type': 'attribute', 'children': ['270', '273']}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}, {'id': '275', 'type': 'lambda', 'children': ['276', '278']}; {'id': '276', 'type': 'lambda_parameters', 'children': ['277']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '278', 'type': 'conditional_expression', 'children': ['279', '280', '283'], 'value': 'if'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '280', 'type': 'comparison_operator', 'children': ['281', '282'], 'value': 'in'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'state_set'}, {'id': '283', 'type': 'string', 'children': [], 'value': "''"}; {'id': '284', 'type': 'return_statement', 'children': ['285']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '286', 'type': 'with_statement', 'children': ['287', '295']}, {'id': '287', 'type': 'with_clause', 'children': ['288']}; {'id': '288', 'type': 'with_item', 'children': ['289']}, {'id': '289', 'type': 'as_pattern', 'children': ['290', '293']}; {'id': '290', 'type': 'call', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'ThreadPool'}; {'id': '292', 'type': 'argument_list', 'children': []}, {'id': '293', 'type': 'as_pattern_target', 'children': ['294']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '295', 'type': 'block', 'children': ['296']}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}, {'id': '297', 'type': 'assignment', 'children': ['298', '299', '300']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'acr_results'}, {'id': '299', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '300', 'type': 'call', 'children': ['301', '304']}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '304', 'type': 'argument_list', 'children': ['305', '308']}, {'id': '305', 'type': 'keyword_argument', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': '_work'}; {'id': '308', 'type': 'keyword_argument', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '310', 'type': 'generator_expression', 'children': ['311', '330']}, {'id': '311', 'type': 'tuple', 'children': ['312', '313', '314', '320', '321', '322']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '314', 'type': 'call', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'get_states'}; {'id': '316', 'type': 'argument_list', 'children': ['317', '318', '319']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '322', 'type': 'conditional_expression', 'children': ['323', '326', '329'], 'value': 'if'}, {'id': '323', 'type': 'subscript', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'column2parameters'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '326', 'type': 'comparison_operator', 'children': ['327', '328'], 'value': 'in'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'column2parameters'}, {'id': '329', 'type': 'None', 'children': []}; {'id': '330', 'type': 'for_in_clause', 'children': ['331', '335']}, {'id': '331', 'type': 'tuple_pattern', 'children': ['332', '333', '334']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '335', 'type': 'call', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '337', 'type': 'argument_list', 'children': ['338', '339', '340']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'prediction_methods'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'models'}, {'id': '341', 'type': 'expression_statement', 'children': ['342']}; {'id': '342', 'type': 'assignment', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '344', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '345', 'type': 'for_statement', 'children': ['346', '347', '348']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'acr_res'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'acr_results'}; {'id': '348', 'type': 'block', 'children': ['349']}, {'id': '349', 'type': 'if_statement', 'children': ['350', '355', '363']}; {'id': '350', 'type': 'call', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '352', 'type': 'argument_list', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'acr_res'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '355', 'type': 'block', 'children': ['356']}; {'id': '356', 'type': 'expression_statement', 'children': ['357']}, {'id': '357', 'type': 'call', 'children': ['358', '361']}; {'id': '358', 'type': 'attribute', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '361', 'type': 'argument_list', 'children': ['362']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'acr_res'}, {'id': '363', 'type': 'else_clause', 'children': ['364']}; {'id': '364', 'type': 'block', 'children': ['365']}, {'id': '365', 'type': 'expression_statement', 'children': ['366']}; {'id': '366', 'type': 'call', 'children': ['367', '370']}, {'id': '367', 'type': 'attribute', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '370', 'type': 'argument_list', 'children': ['371']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'acr_res'}; {'id': '372', 'type': 'return_statement', 'children': ['373']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'result'}
def acr(tree, df, prediction_method=MPPA, model=F81, column2parameters=None, force_joint=True): for c in df.columns: df[c] = df[c].apply(lambda _: '' if pd.isna(_) else _.encode('ASCII', 'replace').decode()) columns = preannotate_tree(df, tree) name_tree(tree) collapse_zero_branches(tree, features_to_be_merged=df.columns) avg_br_len, num_nodes, num_tips = get_tree_stats(tree) logging.getLogger('pastml').debug('\n=============ACR===============================') column2parameters = column2parameters if column2parameters else {} def _work(args): return reconstruct_ancestral_states(*args, avg_br_len=avg_br_len, num_nodes=num_nodes, num_tips=num_tips, force_joint=force_joint) prediction_methods = value2list(len(columns), prediction_method, MPPA) models = value2list(len(columns), model, F81) def get_states(method, model, column): df_states = [_ for _ in df[column].unique() if pd.notnull(_) and _ != ''] if not is_ml(method) or model not in {HKY, JTT}: return np.sort(df_states) states = HKY_STATES if HKY == model else JTT_STATES if not set(df_states) & set(states): raise ValueError('The allowed states for model {} are {}, ' 'but your annotation file specifies {} as states in column {}.' .format(model, ', '.join(states), ', '.join(df_states), column)) state_set = set(states) df[column] = df[column].apply(lambda _: _ if _ in state_set else '') return states with ThreadPool() as pool: acr_results = \ pool.map(func=_work, iterable=((tree, column, get_states(method, model, column), method, model, column2parameters[column] if column in column2parameters else None) for (column, method, model) in zip(columns, prediction_methods, models))) result = [] for acr_res in acr_results: if isinstance(acr_res, list): result.extend(acr_res) else: result.append(acr_res) return result
{'id': '0', 'type': 'module', 'children': ['1', '169', '176', '207', '219']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7', '159']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'export_bert'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'electrodes'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '7', 'type': 'ERROR', 'children': ['8', '41', '49', '61', '64', '65']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '13']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'has_multiple_timesteps'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'for_statement', 'children': ['15', '18', '25']}, {'id': '15', 'type': 'pattern_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'timestep'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'split_timesteps'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'export_bert'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'timestep'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'electrodes'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '40'], 'value': '%'}, {'id': '39', 'type': 'string', 'children': [], 'value': '"_%.3d."'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '%'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"%d\\n"'}, {'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': 'electrodes'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '64', 'type': 'ERROR', 'children': []}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67', '152']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'electrodes'}, {'id': '67', 'type': 'ERROR', 'children': ['68', '84', '93', '96', '117', '134', '151']}; {'id': '68', 'type': 'attribute', 'children': ['69', '81', '83']}, {'id': '69', 'type': 'call', 'children': ['70', '80']}; {'id': '70', 'type': 'attribute', 'children': ['71', '76', '79']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'electrodes'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '75', 'type': 'argument_list', 'children': []}; {'id': '76', 'type': 'ERROR', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'ERROR', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'electrodes'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '84', 'type': 'call', 'children': ['85', '92']}, {'id': '85', 'type': 'attribute', 'children': ['86', '91']}; {'id': '86', 'type': 'attribute', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'electrodes'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '92', 'type': 'argument_list', 'children': []}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '96', 'type': 'subscript', 'children': ['97', '106', '108', '109', '110', '111', '112', '113', '114', '115', '116']}, {'id': '97', 'type': 'call', 'children': ['98', '105']}; {'id': '98', 'type': 'attribute', 'children': ['99', '104']}, {'id': '99', 'type': 'attribute', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'ERROR', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'cols_to_export'}; {'id': '108', 'type': 'string', 'children': [], 'value': '"a"'}, {'id': '109', 'type': 'string', 'children': [], 'value': '"b"'}; {'id': '110', 'type': 'string', 'children': [], 'value': '"m"'}, {'id': '111', 'type': 'string', 'children': [], 'value': '"n"'}; {'id': '112', 'type': 'string', 'children': [], 'value': '"u"'}, {'id': '113', 'type': 'string', 'children': [], 'value': '"i"'}; {'id': '114', 'type': 'string', 'children': [], 'value': '"r"'}, {'id': '115', 'type': 'string', 'children': [], 'value': '"rho_a"'}; {'id': '116', 'type': 'string', 'children': [], 'value': '"error"'}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'drop'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '130', '131']}; {'id': '122', 'type': 'call', 'children': ['123', '128']}, {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'cols_to_export'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'inplace'}, {'id': '133', 'type': 'True', 'children': []}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'rename'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '148']}, {'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '141', 'type': 'dictionary', 'children': ['142', '145']}; {'id': '142', 'type': 'pair', 'children': ['143', '144']}, {'id': '143', 'type': 'string', 'children': [], 'value': '"rho_a"'}; {'id': '144', 'type': 'string', 'children': [], 'value': '"rhoa"'}, {'id': '145', 'type': 'pair', 'children': ['146', '147']}; {'id': '146', 'type': 'string', 'children': [], 'value': '"error"'}, {'id': '147', 'type': 'string', 'children': [], 'value': '"err"'}; {'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '150', 'type': 'True', 'children': []}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'in'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'electrodes'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '158', 'type': 'argument_list', 'children': []}, {'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': 'f'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '%'}, {'id': '167', 'type': 'string', 'children': [], 'value': '"%s "'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '176', 'type': 'for_statement', 'children': ['177', '178', '186']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'electrodes'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'itertuples'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '185', 'type': 'False', 'children': []}; {'id': '186', 'type': 'block', 'children': ['187', '200']}, {'id': '187', 'type': 'for_statement', 'children': ['188', '189', '190']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '190', 'type': 'block', 'children': ['191']}, {'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': 'f'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '%'}; {'id': '198', 'type': 'string', 'children': [], 'value': '"%5.3f "'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '%'}; {'id': '214', 'type': 'string', 'children': [], 'value': '"%d\\n"'}, {'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': 'data'}, {'id': '219', 'type': 'ERROR', 'children': ['220', '223', '224', '293', '299', '300', '326']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '223', 'type': 'ERROR', 'children': []}; {'id': '224', 'type': 'keyword_argument', 'children': ['225', '226', '292']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '226', 'type': 'ERROR', 'children': ['227', '239', '245', '246', '266', '281', '282']}, {'id': '227', 'type': 'comparison_operator', 'children': ['228', '235', '238'], 'value': 'in'}; {'id': '228', 'type': 'call', 'children': ['229', '234']}, {'id': '229', 'type': 'attribute', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'tolist'}; {'id': '234', 'type': 'argument_list', 'children': []}, {'id': '235', 'type': 'ERROR', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'for'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '238', 'type': 'string', 'children': [], 'value': '"abmn"'}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '246', 'type': 'comparison_operator', 'children': ['247', '258', '261'], 'value': 'in'}, {'id': '247', 'type': 'binary_operator', 'children': ['248', '252'], 'value': '+'}; {'id': '248', 'type': 'call', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'string', 'children': [], 'value': '"abmn"'}; {'id': '252', 'type': 'subscript', 'children': ['253', '254', '257']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '254', 'type': 'ERROR', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '258', 'type': 'ERROR', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '265', 'type': 'argument_list', 'children': []}; {'id': '266', 'type': 'call', 'children': ['267', '279']}, {'id': '267', 'type': 'attribute', 'children': ['268', '276', '278']}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '%'}; {'id': '274', 'type': 'string', 'children': [], 'value': '"%s "'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '276', 'type': 'ERROR', 'children': ['277']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '282', 'type': 'comparison_operator', 'children': ['283', '284'], 'value': 'in'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '284', 'type': 'call', 'children': ['285', '288']}, {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'itertuples'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}, {'id': '289', 'type': 'keyword_argument', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '291', 'type': 'False', 'children': []}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '293', 'type': 'comparison_operator', 'children': ['294', '295'], 'value': 'in'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '295', 'type': 'call', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '299', 'type': 'ERROR', 'children': []}; {'id': '300', 'type': 'ERROR', 'children': ['301', '304', '312', '320']}, {'id': '301', 'type': 'comparison_operator', 'children': ['302', '303'], 'value': '<'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '303', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '304', 'type': 'call', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '308', 'type': 'argument_list', 'children': ['309']}, {'id': '309', 'type': 'binary_operator', 'children': ['310', '311'], 'value': '%'}; {'id': '310', 'type': 'string', 'children': [], 'value': '"%d "'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '312', 'type': 'call', 'children': ['313', '316']}, {'id': '313', 'type': 'attribute', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'binary_operator', 'children': ['318', '319'], 'value': '%'}; {'id': '318', 'type': 'string', 'children': [], 'value': '"%E "'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'val'}; {'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': 'write'}; {'id': '324', 'type': 'argument_list', 'children': ['325']}, {'id': '325', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '326', 'type': 'call', 'children': ['327', '330']}, {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'close'}
def export_bert(data, electrodes, filename): if has_multiple_timesteps(data): for i, timestep in enumerate(split_timesteps(data)): export_bert(timestep, electrodes, filename.replace(".", "_%.3d." % i)) f = open(filename, 'w') f.write("%d\n" % len(electrodes)) f.write(" electrodes = electrodes.copy() data = data.copy() electrodes.columns = electrodes.columns.str.lower() data.columns = data.columns.str.lower() cols_to_export = ["a", "b", "m", "n", "u", "i", "r", "rho_a", "error"] data.drop(data.columns.difference(cols_to_export), 1, inplace=True) data.rename(columns={"rho_a": "rhoa", "error": "err"}, inplace=True) for key in electrodes.keys(): f.write("%s " % key) f.write("\n") for row in electrodes.itertuples(index=False): for val in row: f.write("%5.3f " % val) f.write("\n") f.write("%d\n" % len(data)) f.write(" columns = data.columns.tolist() for c in "abmn": columns.remove(c) columns = list("abmn") + columns data = data[columns] for key in data.keys(): f.write("%s " % key) f.write("\n") for row in data.itertuples(index=False): for i, val in enumerate(row): if i < 4: f.write("%d " % val) else: f.write("%E " % val) f.write("\n") f.close()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_dd_skips'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dd_indices_all'}; {'id': '6', 'type': 'block', 'children': ['7', '26', '44', '53', '70', '74', '101']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'config_current_skips'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'binary_operator', 'children': ['16', '21'], 'value': '-'}; {'id': '16', 'type': 'subscript', 'children': ['17', '18', '20']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '18', 'type': 'slice', 'children': ['19']}, {'id': '19', 'type': 'colon', 'children': []}; {'id': '20', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '21', 'type': 'subscript', 'children': ['22', '23', '25']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '23', 'type': 'slice', 'children': ['24']}; {'id': '24', 'type': 'colon', 'children': []}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '38']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'isnan'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'config_current_skips'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'dictionary', 'children': ['41']}, {'id': '41', 'type': 'pair', 'children': ['42', '43']}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '43', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'available_skips_raw'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'unique'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'config_current_skips'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'available_skips'}; {'id': '56', 'type': 'call', 'children': ['57', '68']}, {'id': '57', 'type': 'attribute', 'children': ['58', '67']}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'available_skips_raw'}; {'id': '60', 'type': 'unary_operator', 'children': ['61'], 'value': '~'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'isnan'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'available_skips_raw'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'dd_configs_sorted'}, {'id': '73', 'type': 'dictionary', 'children': []}; {'id': '74', 'type': 'for_statement', 'children': ['75', '76', '77']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'available_skips'}, {'id': '77', 'type': 'block', 'children': ['78', '91']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '81', 'type': 'subscript', 'children': ['82', '90']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '=='}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'config_current_skips'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '98']}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'dd_configs_sorted'}, {'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '-'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'skip'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'dd_indices_all'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '101', 'type': 'return_statement', 'children': ['102']}
def _sort_dd_skips(configs, dd_indices_all): config_current_skips = np.abs(configs[:, 1] - configs[:, 0]) if np.all(np.isnan(config_current_skips)): return {0: []} available_skips_raw = np.unique(config_current_skips) available_skips = available_skips_raw[ ~np.isnan(available_skips_raw) ].astype(int) dd_configs_sorted = {} for skip in available_skips: indices = np.where(config_current_skips == skip)[0] dd_configs_sorted[skip - 1] = dd_indices_all[indices] return dd_configs_sorted
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_label'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'parameter'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ptype'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'flavor'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'mpl'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '68', '78', '90', '104']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17', '35']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'flavor'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'not'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'flavor'}, {'id': '21', 'type': 'tuple', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'latex'"}, {'id': '23', 'type': 'string', 'children': [], 'value': "'mathml'"}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'raise_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': "'flavor not recognized: {}'"}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'flavor'}, {'id': '35', 'type': 'else_clause', 'children': ['36']}; {'id': '36', 'type': 'block', 'children': ['37', '47', '55']}, {'id': '37', 'type': 'if_statement', 'children': ['38', '41']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'is'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'mpl'}; {'id': '40', 'type': 'None', 'children': []}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'raise_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'either the flavor or mpl must be provided'"}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'rendering'}; {'id': '50', 'type': 'subscript', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'mpl'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'rcParams'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'text.usetex'"}, {'id': '55', 'type': 'if_statement', 'children': ['56', '57', '62']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'rendering'}, {'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': 'flavor'}, {'id': '61', 'type': 'string', 'children': [], 'value': "'latex'"}; {'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', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'flavor'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'mathml'"}; {'id': '68', 'type': 'if_statement', 'children': ['69', '72']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'not'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'parameter'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'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': 'Exception'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'string', 'children': [], 'value': "'parameter not known'"}; {'id': '78', 'type': 'if_statement', 'children': ['79', '84']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'not'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ptype'}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'raise_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'string', 'children': [], 'value': "'ptype not known'"}; {'id': '90', 'type': 'if_statement', 'children': ['91', '98']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'not'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'flavor'}, {'id': '93', 'type': 'subscript', 'children': ['94', '97']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'parameter'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ptype'}; {'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': "'flavor not known'"}; {'id': '104', 'type': 'return_statement', 'children': ['105']}, {'id': '105', 'type': 'subscript', 'children': ['106', '111']}; {'id': '106', 'type': 'subscript', 'children': ['107', '110']}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'ptype'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'flavor'}
def get_label(parameter, ptype, flavor=None, mpl=None): if flavor is not None: if flavor not in ('latex', 'mathml'): raise Exception('flavor not recognized: {}'.format(flavor)) else: if mpl is None: raise Exception('either the flavor or mpl must be provided') rendering = mpl.rcParams['text.usetex'] if rendering: flavor = 'latex' else: flavor = 'mathml' if parameter not in labels: raise Exception('parameter not known') if ptype not in labels[parameter]: raise Exception('ptype not known') if flavor not in labels[parameter][ptype]: raise Exception('flavor not known') return labels[parameter][ptype][flavor]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'convert'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'input_format'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'output_format'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'one_spectrum'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '18', '33', '48', '101', '112', '122', '146', '165']}, {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': '=='}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'input_format'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'output_format'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'not'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'input_format'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'from_converters'}; {'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': 'KeyError'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': "'Input format {0} not known!'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'input_format'}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'not'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'output_format'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'to_converters'}, {'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': 'KeyError'}, {'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': "'Output format {0} not known!'"}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'output_format'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '67', '91']}, {'id': '49', 'type': 'boolean_operator', 'children': ['50', '66'], 'value': 'and'}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '59'], 'value': 'and'}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '58'], 'value': '=='}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '65'], 'value': '=='}; {'id': '60', 'type': 'subscript', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'one_spectrum'}, {'id': '67', 'type': 'block', 'children': ['68', '87']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'work_data'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'hstack'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'tuple', 'children': ['77', '82']}, {'id': '77', 'type': 'subscript', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'slice', 'children': ['81']}, {'id': '81', 'type': 'colon', 'children': []}; {'id': '82', 'type': 'subscript', 'children': ['83', '84', '85']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '85', 'type': 'slice', 'children': ['86']}; {'id': '86', 'type': 'colon', 'children': []}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'one_spec_2d'}; {'id': '90', 'type': 'True', 'children': []}, {'id': '91', 'type': 'else_clause', 'children': ['92']}; {'id': '92', 'type': 'block', 'children': ['93', '97']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'work_data'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'one_spec_2d'}; {'id': '100', 'type': 'False', 'children': []}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '106']}, {'id': '103', 'type': 'pattern_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'cre'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'cim'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'from_converters'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'input_format'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'work_data'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'converted_data'}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'to_converters'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'output_format'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'cre'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'cim'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'one_spec_2d'}; {'id': '124', 'type': 'block', 'children': ['125', '135']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '130']}, {'id': '127', 'type': 'pattern_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'part1'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'part2'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'split_data'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'converted_data'}; {'id': '134', 'type': 'True', 'children': []}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'converted_data'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'vstack'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'tuple', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'part1'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'part2'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '155']}, {'id': '147', 'type': 'comparison_operator', 'children': ['148', '154'], 'value': '=='}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'converted_data'}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'squeeze'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'converted_data'}, {'id': '165', 'type': 'return_statement', 'children': ['166']}
def convert(input_format, output_format, data, one_spectrum=False): if input_format == output_format: return data if input_format not in from_converters: raise KeyError('Input format {0} not known!'.format(input_format)) if output_format not in to_converters: raise KeyError('Output format {0} not known!'.format(output_format)) if len(data.shape) == 2 and data.shape[0] == 2 and one_spectrum: work_data = np.hstack((data[0, :], data[1, :])) one_spec_2d = True else: work_data = data one_spec_2d = False cre, cim = from_converters[input_format](work_data) converted_data = to_converters[output_format](cre, cim) if one_spec_2d: part1, part2 = split_data(converted_data, True) converted_data = np.vstack((part1, part2)) if len(data.shape) == 1: converted_data = np.squeeze(converted_data) return converted_data
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_ps_extra'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dataobj'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '30', '59', '105', '114', '127', '136', '150', '156', '164', '187', '196', '200', '287', '322', '328', '334']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '17', '22']}; {'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': 'dataobj'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'df_raw'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dataobj'}; {'id': '22', 'type': 'else_clause', 'children': ['23']}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'df_raw'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dataobj'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '38', '53']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'subquery'"}, {'id': '37', 'type': 'False', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'df_raw'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'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']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'subquery'"}, {'id': '53', 'type': 'else_clause', 'children': ['54']}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'df_raw'}, {'id': '59', 'type': 'function_definition', 'children': ['60', '61', '64']}; {'id': '60', 'type': 'function_name', 'children': [], 'value': 'fancyfy'}, {'id': '61', 'type': 'parameters', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '64', 'type': 'block', 'children': ['65', '86']}, {'id': '65', 'type': 'for_statement', 'children': ['66', '67', '78']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '67', 'type': 'attribute', 'children': ['68', '77']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70', '75']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '70', 'type': 'slice', 'children': ['71', '72', '73']}, {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'colon', 'children': []}, {'id': '73', 'type': 'unary_operator', 'children': ['74'], 'value': '-'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '75', 'type': 'slice', 'children': ['76']}; {'id': '76', 'type': 'colon', 'children': []}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'flat'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'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': 'ax'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'string', 'children': [], 'value': "''"}; {'id': '86', 'type': 'for_statement', 'children': ['87', '88', '97']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '88', 'type': 'attribute', 'children': ['89', '96']}, {'id': '89', 'type': 'subscript', 'children': ['90', '91', '93']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '91', 'type': 'slice', 'children': ['92']}; {'id': '92', 'type': 'colon', 'children': []}, {'id': '93', 'type': 'slice', 'children': ['94', '95']}; {'id': '94', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '95', 'type': 'colon', 'children': []}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'flat'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'string', 'children': [], 'value': "''"}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'string', 'children': [], 'value': "'timestep'"}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '126']}, {'id': '121', 'type': 'attribute', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'groups'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '126', 'type': 'argument_list', 'children': []}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'nrx'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'tuple', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'nry'}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ceil'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '/'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'nrx'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'sizex'}, {'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '*'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'nrx'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'sizey'}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '163'], 'value': '-'}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '*'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'nry'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '163', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '169']}; {'id': '166', 'type': 'pattern_list', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'subplots'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '175', '176', '179', '182']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'nry'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'nrx'}; {'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'sharex'}; {'id': '178', 'type': 'True', 'children': []}, {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'sharey'}, {'id': '181', 'type': 'True', 'children': []}; {'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'figsize'}; {'id': '184', 'type': 'tuple', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'sizex'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'sizey'}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'atleast_2d'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'cbs'}, {'id': '199', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '200', 'type': 'for_statement', 'children': ['201', '206', '213']}, {'id': '201', 'type': 'pattern_list', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '203', 'type': 'tuple_pattern', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'flat'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '213', 'type': 'block', 'children': ['214', '249', '256', '271', '280']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '220']}; {'id': '216', 'type': 'pattern_list', 'children': ['217', '218', '219']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'fig1'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'axes1'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'cb1'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'plot_pseudosection_type2'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '224', '225', '228', '231', '240']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'log10'}; {'id': '230', 'type': 'False', 'children': []}, {'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'cbmin'}, {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '237', 'type': 'argument_list', 'children': ['238', '239']}; {'id': '238', 'type': 'string', 'children': [], 'value': "'cbmin'"}, {'id': '239', 'type': 'None', 'children': []}; {'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'cbmax'}; {'id': '242', 'type': 'call', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '246', 'type': 'argument_list', 'children': ['247', '248']}, {'id': '247', 'type': 'string', 'children': [], 'value': "'cbmax'"}; {'id': '248', 'type': 'None', 'children': []}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'call', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'cbs'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'cb1'}; {'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': 'ax'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'set_title'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'string', 'children': [], 'value': "'timestep: {0}'"}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'call', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'call', 'children': ['273', '278']}, {'id': '273', 'type': 'attribute', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'xaxis'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'set_ticks_position'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'string', 'children': [], 'value': "'bottom'"}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'set_aspect'}, {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'string', 'children': [], 'value': "'equal'"}, {'id': '287', 'type': 'for_statement', 'children': ['288', '289', '312']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'cb'}, {'id': '289', 'type': 'attribute', 'children': ['290', '311']}; {'id': '290', 'type': 'subscript', 'children': ['291', '304', '306']}, {'id': '291', 'type': 'call', 'children': ['292', '300']}; {'id': '292', 'type': 'attribute', 'children': ['293', '299']}, {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'cbs'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'reshape'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '304', 'type': 'slice', 'children': ['305']}, {'id': '305', 'type': 'colon', 'children': []}; {'id': '306', 'type': 'slice', 'children': ['307', '308', '309']}, {'id': '307', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '308', 'type': 'colon', 'children': []}, {'id': '309', 'type': 'unary_operator', 'children': ['310'], 'value': '-'}; {'id': '310', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'flat'}; {'id': '312', 'type': 'block', 'children': ['313']}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'call', 'children': ['315', '320']}, {'id': '315', 'type': 'attribute', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'cb'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'set_visible'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'False', 'children': []}; {'id': '322', 'type': 'expression_statement', 'children': ['323']}, {'id': '323', 'type': 'call', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'fancyfy'}, {'id': '325', 'type': 'argument_list', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'call', 'children': ['330', '333']}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'tight_layout'}, {'id': '333', 'type': 'argument_list', 'children': []}; {'id': '334', 'type': 'return_statement', 'children': ['335']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'fig'}
def plot_ps_extra(dataobj, key, **kwargs): if isinstance(dataobj, pd.DataFrame): df_raw = dataobj else: df_raw = dataobj.data if kwargs.get('subquery', False): df = df_raw.query(kwargs.get('subquery')) else: df = df_raw def fancyfy(axes, N): for ax in axes[0:-1, :].flat: ax.set_xlabel('') for ax in axes[:, 1:].flat: ax.set_ylabel('') g = df.groupby('timestep') N = len(g.groups.keys()) nrx = min((N, 5)) nry = int(np.ceil(N / nrx)) sizex = nrx * 3 sizey = nry * 4 - 1 fig, axes = plt.subplots( nry, nrx, sharex=True, sharey=True, figsize=(sizex, sizey), ) axes = np.atleast_2d(axes) cbs = [] for ax, (name, group) in zip(axes.flat, g): fig1, axes1, cb1 = plot_pseudosection_type2( group, key, ax=ax, log10=False, cbmin=kwargs.get('cbmin', None), cbmax=kwargs.get('cbmax', None), ) cbs.append(cb1) ax.set_title('timestep: {0}'.format(int(name))) ax.xaxis.set_ticks_position('bottom') ax.set_aspect('equal') for cb in np.array(cbs).reshape(axes.shape)[:, 0:-1].flat: cb.ax.set_visible(False) fancyfy(axes, N) fig.tight_layout() return fig
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_pseudodepths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'nr_electrodes'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'spacing'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'grid'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ctypes'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dd_merge'}, {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'dictionary_splat_pattern', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '20', 'type': 'block', 'children': ['21', '34', '47', '54', '69', '73', '77', '372']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pseudo_d_functions'}; {'id': '24', 'type': 'dictionary', 'children': ['25', '28', '31']}, {'id': '25', 'type': 'pair', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'dd'"}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_pseudodepths_dd_simple'}; {'id': '28', 'type': 'pair', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': "'schlumberger'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_pseudodepths_schlumberger'}, {'id': '31', 'type': 'pair', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'wenner'"}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '_pseudodepths_wenner'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'titles'}, {'id': '37', 'type': 'dictionary', 'children': ['38', '41', '44']}; {'id': '38', 'type': 'pair', 'children': ['39', '40']}, {'id': '39', 'type': 'string', 'children': [], 'value': "'dd'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'dipole-dipole configurations'"}, {'id': '41', 'type': 'pair', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'schlumberger'"}, {'id': '43', 'type': 'string', 'children': [], 'value': "'Schlumberger configurations'"}; {'id': '44', 'type': 'pair', 'children': ['45', '46']}, {'id': '45', 'type': 'string', 'children': [], 'value': "'wenner'"}; {'id': '46', 'type': 'string', 'children': [], 'value': "'Wenner configurations'"}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'only_types'}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '52'], 'value': 'or'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ctypes'}; {'id': '52', 'type': 'list', 'children': ['53'], 'value': "['dd', ]"}, {'id': '53', 'type': 'string', 'children': [], 'value': "'dd'"}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'fT'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '65', 'type': 'dictionary', 'children': ['66']}; {'id': '66', 'type': 'pair', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'only_types'"}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'only_types'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'figs'}; {'id': '72', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '76', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '77', 'type': 'for_statement', 'children': ['78', '79', '87']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '86', 'type': 'argument_list', 'children': []}, {'id': '87', 'type': 'block', 'children': ['88', '94', '100', '106', '181', '185']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'plotting: '"}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '98']}, {'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '=='}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '97', 'type': 'string', 'children': [], 'value': "'not_sorted'"}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'continue_statement', 'children': []}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'index_dict'}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '113', '154']}, {'id': '107', 'type': 'boolean_operator', 'children': ['108', '111'], 'value': 'and'}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '=='}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'dd'"}, {'id': '111', 'type': 'not_operator', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'dd_merge'}, {'id': '113', 'type': 'block', 'children': ['114', '118', '122']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'plot_list'}, {'id': '117', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'labels_add'}, {'id': '121', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '122', 'type': 'for_statement', 'children': ['123', '124', '132']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'index_dict'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '131', 'type': 'argument_list', 'children': []}; {'id': '132', 'type': 'block', 'children': ['133', '142']}, {'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': 'plot_list'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'index_dict'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'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': 'labels_add'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'string', 'children': [], 'value': "' - skip {0}'"}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '154', 'type': 'else_clause', 'children': ['155']}, {'id': '155', 'type': 'block', 'children': ['156', '170', '176']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'plot_list'}, {'id': '159', 'type': 'list', 'children': ['160'], 'value': '[np.hstack(index_dict.values()), ]'}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'hstack'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'index_dict'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '169', 'type': 'argument_list', 'children': []}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'string', 'children': [], 'value': "'schlumberger'"}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'plot_list'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'labels_add'}, {'id': '179', 'type': 'list', 'children': ['180'], 'value': "['', ]"}; {'id': '180', 'type': 'string', 'children': [], 'value': "''"}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '184', 'type': 'None', 'children': []}, {'id': '185', 'type': 'for_statement', 'children': ['186', '189', '194']}; {'id': '186', 'type': 'pattern_list', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'label_add'}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '191', 'type': 'argument_list', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'plot_list'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'labels_add'}; {'id': '194', 'type': 'block', 'children': ['195', '204', '210', '223', '242', '256', '320', '331', '338', '345', '352', '358', '365']}, {'id': '195', 'type': 'if_statement', 'children': ['196', '202']}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '201'], 'value': '=='}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '201', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '202', 'type': 'block', 'children': ['203']}, {'id': '203', 'type': 'continue_statement', 'children': []}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'ddc'}, {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '215']}; {'id': '212', 'type': 'pattern_list', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'px'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'pz'}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'pseudo_d_functions'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '219', 'type': 'argument_list', 'children': ['220', '221', '222']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'ddc'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'spacing'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'grid'}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '228']}, {'id': '225', 'type': 'pattern_list', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'fig'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'plt'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'subplots'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'figsize'}, {'id': '235', 'type': 'tuple', 'children': ['236', '239']}; {'id': '236', 'type': 'binary_operator', 'children': ['237', '238'], 'value': '/'}, {'id': '237', 'type': 'integer', 'children': [], 'value': '15'}; {'id': '238', 'type': 'float', 'children': [], 'value': '2.54'}, {'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '/'}; {'id': '240', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '241', 'type': 'float', 'children': [], 'value': '2.54'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'scatter'}, {'id': '247', 'type': 'argument_list', 'children': ['248', '249', '250', '253']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'px'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'pz'}; {'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '252', 'type': 'string', 'children': [], 'value': "'k'"}, {'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'alpha'}, {'id': '255', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '256', 'type': 'if_statement', 'children': ['257', '260', '291']}, {'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': 'is'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'grid'}, {'id': '259', 'type': 'None', 'children': []}; {'id': '260', 'type': 'block', 'children': ['261', '269']}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'electrodes'}; {'id': '264', 'type': 'call', 'children': ['265', '268']}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'grid'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'get_electrode_positions'}; {'id': '268', 'type': 'argument_list', 'children': []}, {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'scatter'}; {'id': '274', 'type': 'argument_list', 'children': ['275', '280', '285', '288']}, {'id': '275', 'type': 'subscript', 'children': ['276', '277', '279']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'electrodes'}, {'id': '277', 'type': 'slice', 'children': ['278']}; {'id': '278', 'type': 'colon', 'children': []}, {'id': '279', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '280', 'type': 'subscript', 'children': ['281', '282', '284']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'electrodes'}; {'id': '282', 'type': 'slice', 'children': ['283']}, {'id': '283', 'type': 'colon', 'children': []}; {'id': '284', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '285', 'type': 'keyword_argument', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '287', 'type': 'string', 'children': [], 'value': "'b'"}; {'id': '288', 'type': 'keyword_argument', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '290', 'type': 'string', 'children': [], 'value': "'electrodes'"}, {'id': '291', 'type': 'else_clause', 'children': ['292']}; {'id': '292', 'type': 'block', 'children': ['293']}, {'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': 'ax'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'scatter'}; {'id': '298', 'type': 'argument_list', 'children': ['299', '308', '314', '317']}, {'id': '299', 'type': 'binary_operator', 'children': ['300', '307'], 'value': '*'}; {'id': '300', 'type': 'call', 'children': ['301', '304']}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '304', 'type': 'argument_list', 'children': ['305', '306']}, {'id': '305', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'nr_electrodes'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'spacing'}; {'id': '308', 'type': 'call', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'nr_electrodes'}; {'id': '314', 'type': 'keyword_argument', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '316', 'type': 'string', 'children': [], 'value': "'b'"}, {'id': '317', 'type': 'keyword_argument', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '319', 'type': 'string', 'children': [], 'value': "'electrodes'"}; {'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': 'ax'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'set_title'}, {'id': '325', 'type': 'argument_list', 'children': ['326']}; {'id': '326', 'type': 'binary_operator', 'children': ['327', '330'], 'value': '+'}, {'id': '327', 'type': 'subscript', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'titles'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'label_add'}, {'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': 'ax'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'set_aspect'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}, {'id': '337', 'type': 'string', 'children': [], 'value': "'equal'"}; {'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': 'ax'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}, {'id': '343', 'type': 'argument_list', 'children': ['344']}; {'id': '344', 'type': 'string', 'children': [], 'value': "'x [m]'"}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'call', 'children': ['347', '350']}, {'id': '347', 'type': 'attribute', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}; {'id': '350', 'type': 'argument_list', 'children': ['351']}, {'id': '351', 'type': 'string', 'children': [], 'value': "'x [z]'"}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}, {'id': '353', 'type': 'call', 'children': ['354', '357']}; {'id': '354', 'type': 'attribute', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'tight_layout'}, {'id': '357', 'type': 'argument_list', 'children': []}; {'id': '358', 'type': 'expression_statement', 'children': ['359']}, {'id': '359', 'type': 'call', 'children': ['360', '363']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'figs'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '363', 'type': 'argument_list', 'children': ['364']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'fig'}, {'id': '365', 'type': 'expression_statement', 'children': ['366']}; {'id': '366', 'type': 'call', 'children': ['367', '370']}, {'id': '367', 'type': 'attribute', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '370', 'type': 'argument_list', 'children': ['371']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '372', 'type': 'if_statement', 'children': ['373', '379', '388']}, {'id': '373', 'type': 'comparison_operator', 'children': ['374', '378'], 'value': '=='}; {'id': '374', 'type': 'call', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '376', 'type': 'argument_list', 'children': ['377']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'figs'}; {'id': '378', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '379', 'type': 'block', 'children': ['380']}; {'id': '380', 'type': 'return_statement', 'children': ['381']}, {'id': '381', 'type': 'expression_list', 'children': ['382', '385']}; {'id': '382', 'type': 'subscript', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'figs'}; {'id': '384', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '385', 'type': 'subscript', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '387', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '388', 'type': 'else_clause', 'children': ['389']}, {'id': '389', 'type': 'block', 'children': ['390']}; {'id': '390', 'type': 'return_statement', 'children': ['391']}, {'id': '391', 'type': 'expression_list', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'figs'}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'axes'}
def plot_pseudodepths(configs, nr_electrodes, spacing=1, grid=None, ctypes=None, dd_merge=False, **kwargs): pseudo_d_functions = { 'dd': _pseudodepths_dd_simple, 'schlumberger': _pseudodepths_schlumberger, 'wenner': _pseudodepths_wenner, } titles = { 'dd': 'dipole-dipole configurations', 'schlumberger': 'Schlumberger configurations', 'wenner': 'Wenner configurations', } only_types = ctypes or ['dd', ] results = fT.filter(configs, settings={'only_types': only_types, }) figs = [] axes = [] for key in sorted(results.keys()): print('plotting: ', key) if key == 'not_sorted': continue index_dict = results[key] if key == 'dd' and not dd_merge: plot_list = [] labels_add = [] for skip in sorted(index_dict.keys()): plot_list.append(index_dict[skip]) labels_add.append(' - skip {0}'.format(skip)) else: plot_list = [np.hstack(index_dict.values()), ] print('schlumberger', plot_list) labels_add = ['', ] grid = None for indices, label_add in zip(plot_list, labels_add): if len(indices) == 0: continue ddc = configs[indices] px, pz = pseudo_d_functions[key](ddc, spacing, grid) fig, ax = plt.subplots(figsize=(15 / 2.54, 5 / 2.54)) ax.scatter(px, pz, color='k', alpha=0.5) if grid is not None: electrodes = grid.get_electrode_positions() ax.scatter( electrodes[:, 0], electrodes[:, 1], color='b', label='electrodes', ) else: ax.scatter( np.arange(0, nr_electrodes) * spacing, np.zeros(nr_electrodes), color='b', label='electrodes', ) ax.set_title(titles[key] + label_add) ax.set_aspect('equal') ax.set_xlabel('x [m]') ax.set_ylabel('x [z]') fig.tight_layout() figs.append(fig) axes.append(ax) if len(figs) == 1: return figs[0], axes[0] else: return figs, axes
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'complete'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'uio'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'dropped'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '19']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '17']}, {'id': '11', 'type': 'boolean_operator', 'children': ['12', '15'], 'value': 'and'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dropped'}, {'id': '15', 'type': 'not_operator', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dropped'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': []}, {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '24']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '21', 'type': 'list', 'children': ['22', '23'], 'value': "['src', 'dst']"}; {'id': '22', 'type': 'string', 'children': [], 'value': "'src'"}, {'id': '23', 'type': 'string', 'children': [], 'value': "'dst'"}; {'id': '24', 'type': 'block', 'children': ['25', '33', '44', '51', '62', '149', '174']}, {'id': '25', 'type': 'if_statement', 'children': ['26', '31']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'continue_statement', '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': 'uio'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'show'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '43'], 'value': '+'}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'\\nEnter '"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '43', 'type': 'string', 'children': [], 'value': "' for transaction:'"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'uio'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'show'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': "''"}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'uio'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'show'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'summary'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'try_statement', 'children': ['63', '137']}, {'id': '63', 'type': 'block', 'children': ['64', '68', '74']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'endpoints'}, {'id': '67', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'remaining'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'amount'}; {'id': '74', 'type': 'while_statement', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'remaining'}; {'id': '76', 'type': 'block', 'children': ['77', '87', '105', '116']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'account'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'uio'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86']}, {'id': '85', 'type': 'string', 'children': [], 'value': "' Enter account'"}; {'id': '86', 'type': 'None', 'children': []}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'amount'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'uio'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'decimal'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96', '99', '102']}, {'id': '95', 'type': 'string', 'children': [], 'value': "' Enter amount'"}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'remaining'}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'remaining'}, {'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': 'endpoints'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'Endpoint'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'account'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'amount'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'remaining'}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '123', '124'], 'value': '-'}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'amount'}, {'id': '123', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '136']}; {'id': '130', 'type': 'lambda', 'children': ['131', '133']}, {'id': '131', 'type': 'lambda_parameters', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'amount'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'endpoints'}, {'id': '137', 'type': 'except_clause', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ui'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'RejectWarning'}, {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'string', 'children': [], 'value': '"bye!"'}, {'id': '149', 'type': 'if_statement', 'children': ['150', '153']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': '=='}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'src'"}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'endpoints'}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '173']}; {'id': '160', 'type': 'lambda', 'children': ['161', '163']}, {'id': '161', 'type': 'lambda_parameters', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'Endpoint'}, {'id': '165', 'type': 'argument_list', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'account'}, {'id': '169', 'type': 'unary_operator', 'children': ['170'], 'value': '-'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'amount'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'endpoints'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '177', 'type': 'argument_list', 'children': ['178', '179', '180']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'end'}
def complete(self, uio, dropped=False): if self.dropped and not dropped: return for end in ['src', 'dst']: if getattr(self, end): continue uio.show('\nEnter ' + end + ' for transaction:') uio.show('') uio.show(self.summary()) try: endpoints = [] remaining = self.amount while remaining: account = uio.text(' Enter account', None) amount = uio.decimal( ' Enter amount', default=remaining, lower=0, upper=remaining ) endpoints.append(Endpoint(account, amount)) remaining = self.amount \ - sum(map(lambda x: x.amount, endpoints)) except ui.RejectWarning: sys.exit("bye!") if end == 'src': endpoints = map( lambda x: Endpoint(x.account, -x.amount), endpoints ) setattr(self, end, endpoints)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'gen_dipole_dipole'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'skipc'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'skipv'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'stepc'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'stepv'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'nr_voltage_dipoles'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'before_current'}; {'id': '20', 'type': 'False', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'start_skip'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28', '55', '64', '68', '220', '229', '259']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '38', '44']}, {'id': '29', 'type': 'boolean_operator', 'children': ['30', '33'], 'value': 'and'}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': 'is'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'nr_electrodes'}, {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'raise_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': "'You must provide the number of electrodes'"}; {'id': '44', 'type': 'elif_clause', 'children': ['45', '48']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'is'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'nr_electrodes'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'skipv'}; {'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': 'skipv'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'skipc'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '67', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '68', 'type': 'for_statement', 'children': ['69', '70', '82']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74', '81']}, {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '80'], 'value': '-'}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '79'], 'value': '-'}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '-'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'skipv'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'skipc'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'stepc'}; {'id': '82', 'type': 'block', 'children': ['83', '91', '95', '159', '163']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '90'], 'value': '+'}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '+'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'skipc'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'nr'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'before_current'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'for_statement', 'children': ['99', '100', '112']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '108', '110']}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '107'], 'value': '-'}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '-'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'start_skip'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'unary_operator', 'children': ['109'], 'value': '-'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'unary_operator', 'children': ['111'], 'value': '-'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'stepv'}; {'id': '112', 'type': 'block', 'children': ['113', '117', '123', '131', '137', '152']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'augmented_assignment', 'children': ['115', '116'], 'value': '+='}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'nr'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '117', 'type': 'if_statement', 'children': ['118', '121']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '>'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'nr'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'nr_voltage_dipoles'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'continue_statement', 'children': []}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '130'], 'value': '-'}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '-'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'skipv'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '131', 'type': 'if_statement', 'children': ['132', '135']}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': '<'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'continue_statement', 'children': []}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '140', 'type': 'binary_operator', 'children': ['141', '151'], 'value': '+'}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'tuple', 'children': ['147', '148', '149', '150']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'quadpole'}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'nr'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '163', 'type': 'for_statement', 'children': ['164', '165', '179']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '167', 'type': 'argument_list', 'children': ['168', '173', '178']}; {'id': '168', 'type': 'binary_operator', 'children': ['169', '172'], 'value': '+'}, {'id': '169', 'type': 'binary_operator', 'children': ['170', '171'], 'value': '+'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'start_skip'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '173', 'type': 'binary_operator', 'children': ['174', '177'], 'value': '-'}; {'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '-'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'skipv'}, {'id': '177', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'stepv'}, {'id': '179', 'type': 'block', 'children': ['180', '184', '190', '198', '213']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'augmented_assignment', 'children': ['182', '183'], 'value': '+='}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'nr'}, {'id': '183', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '184', 'type': 'if_statement', 'children': ['185', '188']}, {'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': '>'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'nr'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'nr_voltage_dipoles'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'continue_statement', 'children': []}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '193', 'type': 'binary_operator', 'children': ['194', '197'], 'value': '+'}; {'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '+'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'skipv'}, {'id': '197', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'quadpole'}, {'id': '201', 'type': 'binary_operator', 'children': ['202', '212'], 'value': '+'}; {'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': 'tuple', 'children': ['208', '209', '210', '211']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '212', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '229', 'type': 'if_statement', 'children': ['230', '235', '242']}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '234'], 'value': 'is'}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '234', 'type': 'None', 'children': []}, {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'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', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '249', 'type': 'call', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'vstack'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'tuple', 'children': ['255', '258']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '259', 'type': 'return_statement', 'children': ['260']}
def gen_dipole_dipole(self, skipc, skipv=None, stepc=1, stepv=1, nr_voltage_dipoles=10, before_current=False, start_skip=0, N=None): if N is None and self.nr_electrodes is None: raise Exception('You must provide the number of electrodes') elif N is None: N = self.nr_electrodes if skipv is None: skipv = skipc configs = [] for a in range(0, N - skipv - skipc - 3, stepc): b = a + skipc + 1 nr = 0 if before_current: for n in range(a - start_skip - 1, -1, -stepv): nr += 1 if nr > nr_voltage_dipoles: continue m = n - skipv - 1 if m < 0: continue quadpole = np.array((a, b, m, n)) + 1 configs.append(quadpole) nr = 0 for m in range(b + start_skip + 1, N - skipv - 1, stepv): nr += 1 if nr > nr_voltage_dipoles: continue n = m + skipv + 1 quadpole = np.array((a, b, m, n)) + 1 configs.append(quadpole) configs = np.array(configs) if self.configs is None: self.configs = configs else: self.configs = np.vstack((self.configs, configs)) return configs
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'split_into_normal_and_reciprocal'}, {'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': 'pad'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'return_indices'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '57', '65', '73', '86', '90', '94', '98', '102', '106', '110', '315', '333', '340', '346', '382', '391', '400']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'hstack'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'tuple', 'children': ['21', '39']}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '36']}; {'id': '26', 'type': 'subscript', 'children': ['27', '30', '32']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '30', 'type': 'slice', 'children': ['31']}, {'id': '31', 'type': 'colon', 'children': []}; {'id': '32', 'type': 'slice', 'children': ['33', '34', '35']}, {'id': '33', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '34', 'type': 'colon', 'children': []}, {'id': '35', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '54']}; {'id': '44', 'type': 'subscript', 'children': ['45', '48', '50']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '48', 'type': 'slice', 'children': ['49']}, {'id': '49', 'type': 'colon', 'children': []}; {'id': '50', 'type': 'slice', 'children': ['51', '52', '53']}, {'id': '51', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '52', 'type': 'colon', 'children': []}, {'id': '53', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'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': 'ab_min'}; {'id': '60', 'type': 'subscript', 'children': ['61', '62', '64']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '62', 'type': 'slice', 'children': ['63']}, {'id': '63', 'type': 'colon', 'children': []}; {'id': '64', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'mn_min'}; {'id': '68', 'type': 'subscript', 'children': ['69', '70', '72']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '70', 'type': 'slice', 'children': ['71']}, {'id': '71', 'type': 'colon', 'children': []}; {'id': '72', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'indices_normal'}; {'id': '76', 'type': 'subscript', 'children': ['77', '85']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'where'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '<'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ab_min'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'mn_min'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'indices_used'}, {'id': '89', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'normal'}, {'id': '93', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'normal_indices'}, {'id': '97', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'reciprocal_indices'}, {'id': '101', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'reciprocal'}, {'id': '105', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'duplicates'}, {'id': '109', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '110', 'type': 'for_statement', 'children': ['111', '112', '113']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'indices_normal'}, {'id': '113', 'type': 'block', 'children': ['114', '121', '134', '141', '198']}; {'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': 'indices_used'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'index'}, {'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': 'normal'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'subscript', 'children': ['128', '131', '132']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '132', 'type': 'slice', 'children': ['133']}, {'id': '133', 'type': 'colon', 'children': []}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'normal_indices'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'index_rec'}; {'id': '144', 'type': 'subscript', 'children': ['145', '197']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'where'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '186'], 'value': '&'}, {'id': '151', 'type': 'binary_operator', 'children': ['152', '175'], 'value': '&'}; {'id': '152', 'type': 'binary_operator', 'children': ['153', '164'], 'value': '&'}, {'id': '153', 'type': 'parenthesized_expression', 'children': ['154'], 'value': '()'}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '160'], 'value': '=='}, {'id': '155', 'type': 'subscript', 'children': ['156', '157', '159']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '157', 'type': 'slice', 'children': ['158']}; {'id': '158', 'type': 'colon', 'children': []}, {'id': '159', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '160', 'type': 'subscript', 'children': ['161', '162', '163']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '163', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '164', 'type': 'parenthesized_expression', 'children': ['165'], 'value': '()'}, {'id': '165', 'type': 'comparison_operator', 'children': ['166', '171'], 'value': '=='}; {'id': '166', 'type': 'subscript', 'children': ['167', '168', '170']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '168', 'type': 'slice', 'children': ['169']}, {'id': '169', 'type': 'colon', 'children': []}; {'id': '170', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '171', 'type': 'subscript', 'children': ['172', '173', '174']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '175', 'type': 'parenthesized_expression', 'children': ['176'], 'value': '()'}; {'id': '176', 'type': 'comparison_operator', 'children': ['177', '182'], 'value': '=='}, {'id': '177', 'type': 'subscript', 'children': ['178', '179', '181']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '179', 'type': 'slice', 'children': ['180']}; {'id': '180', 'type': 'colon', 'children': []}, {'id': '181', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '182', 'type': 'subscript', 'children': ['183', '184', '185']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '185', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '186', 'type': 'parenthesized_expression', 'children': ['187'], 'value': '()'}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '193'], 'value': '=='}; {'id': '188', 'type': 'subscript', 'children': ['189', '190', '192']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '190', 'type': 'slice', 'children': ['191']}, {'id': '191', 'type': 'colon', 'children': []}; {'id': '192', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '193', 'type': 'subscript', 'children': ['194', '195', '196']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '197', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '198', 'type': 'if_statement', 'children': ['199', '207', '224', '265']}, {'id': '199', 'type': 'boolean_operator', 'children': ['200', '206'], 'value': 'and'}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '205'], 'value': '=='}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'index_rec'}, {'id': '205', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'pad'}, {'id': '207', 'type': 'block', 'children': ['208']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'reciprocal'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'binary_operator', 'children': ['215', '221'], 'value': '*'}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'ones'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'nan'}; {'id': '224', 'type': 'elif_clause', 'children': ['225', '231']}, {'id': '225', 'type': 'comparison_operator', 'children': ['226', '230'], 'value': '=='}; {'id': '226', 'type': 'call', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'index_rec'}; {'id': '230', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '231', 'type': 'block', 'children': ['232', '247', '256']}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'reciprocal'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'subscript', 'children': ['239', '242', '245']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '242', 'type': 'subscript', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'index_rec'}; {'id': '244', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '245', 'type': 'slice', 'children': ['246']}; {'id': '246', 'type': 'colon', 'children': []}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'call', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'indices_used'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}, {'id': '253', 'type': 'subscript', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'index_rec'}, {'id': '255', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'reciprocal_indices'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'index_rec'}; {'id': '264', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '265', 'type': 'elif_clause', 'children': ['266', '272']}; {'id': '266', 'type': 'call', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'comparison_operator', 'children': ['270', '271'], 'value': '>'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'index_rec'}, {'id': '271', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '272', 'type': 'block', 'children': ['273', '288', '297', '308']}, {'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': 'reciprocal'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'subscript', 'children': ['280', '283', '286']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '283', 'type': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'index_rec'}, {'id': '285', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '286', 'type': 'slice', 'children': ['287']}, {'id': '287', 'type': 'colon', 'children': []}; {'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': 'reciprocal_indices'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'subscript', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'index_rec'}; {'id': '296', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'augmented_assignment', 'children': ['299', '300'], 'value': '+='}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'duplicates'}; {'id': '300', 'type': 'call', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}, {'id': '303', 'type': 'subscript', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'index_rec'}, {'id': '305', 'type': 'slice', 'children': ['306', '307']}; {'id': '306', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '307', 'type': 'colon', 'children': []}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'augmented_assignment', 'children': ['310', '311'], 'value': '+='}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'indices_used'}, {'id': '311', 'type': 'call', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '313', 'type': 'argument_list', 'children': ['314']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'index_rec'}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'assignment', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'set_all_indices'}; {'id': '318', 'type': 'call', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'call', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'call', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '326', 'type': 'argument_list', 'children': ['327', '328']}, {'id': '327', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '328', 'type': 'subscript', 'children': ['329', '332']}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '332', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '333', 'type': 'expression_statement', 'children': ['334']}; {'id': '334', 'type': 'assignment', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'set_used_indices'}; {'id': '336', 'type': 'call', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '338', 'type': 'argument_list', 'children': ['339']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'indices_used'}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}, {'id': '341', 'type': 'assignment', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'reciprocal_only_indices'}, {'id': '343', 'type': 'binary_operator', 'children': ['344', '345'], 'value': '-'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'set_all_indices'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'set_used_indices'}; {'id': '346', 'type': 'for_statement', 'children': ['347', '348', '349']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'reciprocal_only_indices'}, {'id': '349', 'type': 'block', 'children': ['350', '369']}; {'id': '350', 'type': 'if_statement', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'pad'}; {'id': '352', 'type': 'block', 'children': ['353']}, {'id': '353', 'type': 'expression_statement', 'children': ['354']}; {'id': '354', 'type': 'call', 'children': ['355', '358']}, {'id': '355', 'type': 'attribute', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'normal'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '358', 'type': 'argument_list', 'children': ['359']}, {'id': '359', 'type': 'binary_operator', 'children': ['360', '366'], 'value': '*'}; {'id': '360', 'type': 'call', 'children': ['361', '364']}, {'id': '361', 'type': 'attribute', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}, {'id': '365', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'nan'}, {'id': '369', 'type': 'expression_statement', 'children': ['370']}; {'id': '370', 'type': 'call', 'children': ['371', '374']}, {'id': '371', 'type': 'attribute', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'reciprocal'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '374', 'type': 'argument_list', 'children': ['375']}, {'id': '375', 'type': 'subscript', 'children': ['376', '379', '380']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '380', 'type': 'slice', 'children': ['381']}, {'id': '381', 'type': 'colon', 'children': []}; {'id': '382', 'type': 'expression_statement', 'children': ['383']}, {'id': '383', 'type': 'assignment', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'normals'}, {'id': '385', 'type': 'call', 'children': ['386', '389']}; {'id': '386', 'type': 'attribute', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '389', 'type': 'argument_list', 'children': ['390']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'normal'}, {'id': '391', 'type': 'expression_statement', 'children': ['392']}; {'id': '392', 'type': 'assignment', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}; {'id': '394', 'type': 'call', 'children': ['395', '398']}, {'id': '395', 'type': 'attribute', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '398', 'type': 'argument_list', 'children': ['399']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'reciprocal'}; {'id': '400', 'type': 'if_statement', 'children': ['401', '402', '409']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'return_indices'}; {'id': '402', 'type': 'block', 'children': ['403']}, {'id': '403', 'type': 'return_statement', 'children': ['404']}; {'id': '404', 'type': 'expression_list', 'children': ['405', '406', '407', '408']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'normals'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'normal_indices'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'reciprocal_indices'}, {'id': '409', 'type': 'else_clause', 'children': ['410']}; {'id': '410', 'type': 'block', 'children': ['411']}, {'id': '411', 'type': 'return_statement', 'children': ['412']}; {'id': '412', 'type': 'expression_list', 'children': ['413', '414']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'normals'}
def split_into_normal_and_reciprocal(self, pad=False, return_indices=False): configs = np.hstack((np.sort(self.configs[:, 0:2], axis=1), np.sort(self.configs[:, 2:4], axis=1))) ab_min = configs[:, 0] mn_min = configs[:, 2] indices_normal = np.where(ab_min < mn_min)[0] indices_used = [] normal = [] normal_indices = [] reciprocal_indices = [] reciprocal = [] duplicates = [] for index in indices_normal: indices_used.append(index) normal.append(self.configs[index, :]) normal_indices.append(index) index_rec = np.where( (configs[:, 0] == configs[index, 2]) & (configs[:, 1] == configs[index, 3]) & (configs[:, 2] == configs[index, 0]) & (configs[:, 3] == configs[index, 1]))[0] if len(index_rec) == 0 and pad: reciprocal.append(np.ones(4) * np.nan) elif len(index_rec) == 1: reciprocal.append(self.configs[index_rec[0], :]) indices_used.append(index_rec[0]) reciprocal_indices.append(index_rec[0]) elif len(index_rec > 1): reciprocal.append(self.configs[index_rec[0], :]) reciprocal_indices.append(index_rec[0]) duplicates += list(index_rec[1:]) indices_used += list(index_rec) set_all_indices = set(list(range(0, configs.shape[0]))) set_used_indices = set(indices_used) reciprocal_only_indices = set_all_indices - set_used_indices for index in reciprocal_only_indices: if pad: normal.append(np.ones(4) * np.nan) reciprocal.append(self.configs[index, :]) normals = np.array(normal) reciprocals = np.array(reciprocal) if return_indices: return normals, reciprocals, normal_indices, reciprocal_indices else: return normals, reciprocals
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'gen_reciprocals'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '27', '53', '79', '108', '114', '132']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}; {'id': '12', 'type': 'subscript', 'children': ['13', '20', '22']}, {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'slice', 'children': ['21']}, {'id': '21', 'type': 'colon', 'children': []}; {'id': '22', 'type': 'slice', 'children': ['23', '24', '25']}, {'id': '23', 'type': 'colon', 'children': []}; {'id': '24', 'type': 'colon', 'children': []}, {'id': '25', 'type': 'unary_operator', 'children': ['26'], 'value': '-'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '37']}, {'id': '29', 'type': 'subscript', 'children': ['30', '31', '33']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}, {'id': '31', 'type': 'slice', 'children': ['32']}; {'id': '32', 'type': 'colon', 'children': []}, {'id': '33', 'type': 'slice', 'children': ['34', '35', '36']}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '35', 'type': 'colon', 'children': []}; {'id': '36', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '50']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44', '46']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}; {'id': '44', 'type': 'slice', 'children': ['45']}, {'id': '45', 'type': 'colon', 'children': []}; {'id': '46', 'type': 'slice', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'colon', 'children': []}, {'id': '49', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '63']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57', '59']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}, {'id': '57', 'type': 'slice', 'children': ['58']}; {'id': '58', 'type': 'colon', 'children': []}, {'id': '59', 'type': 'slice', 'children': ['60', '61', '62']}; {'id': '60', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '61', 'type': 'colon', 'children': []}; {'id': '62', 'type': 'integer', 'children': [], 'value': '4'}, {'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': 'sort'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '76']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70', '72']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}; {'id': '70', 'type': 'slice', 'children': ['71']}, {'id': '71', 'type': 'colon', 'children': []}; {'id': '72', 'type': 'slice', 'children': ['73', '74', '75']}, {'id': '73', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '74', 'type': 'colon', 'children': []}, {'id': '75', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'lexsort'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'tuple', 'children': ['88', '93', '98', '103']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90', '92']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}; {'id': '90', 'type': 'slice', 'children': ['91']}, {'id': '91', 'type': 'colon', 'children': []}; {'id': '92', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '93', 'type': 'subscript', 'children': ['94', '95', '97']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}, {'id': '95', 'type': 'slice', 'children': ['96']}; {'id': '96', 'type': 'colon', 'children': []}, {'id': '97', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '98', 'type': 'subscript', 'children': ['99', '100', '102']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}; {'id': '100', 'type': 'slice', 'children': ['101']}, {'id': '101', 'type': 'colon', 'children': []}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '103', 'type': 'subscript', 'children': ['104', '105', '107']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}, {'id': '105', 'type': 'slice', 'children': ['106']}; {'id': '106', 'type': 'colon', 'children': []}, {'id': '107', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'vstack'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'tuple', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'configs'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}; {'id': '132', 'type': 'return_statement', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'reciprocals'}
def gen_reciprocals(self, append=False): reciprocals = self.configs.copy()[:, ::-1] reciprocals[:, 0:2] = np.sort(reciprocals[:, 0:2], axis=1) reciprocals[:, 2:4] = np.sort(reciprocals[:, 2:4], axis=1) ind = np.lexsort((reciprocals[:, 3], reciprocals[:, 2], reciprocals[:, 1], reciprocals[:, 0])) reciprocals = reciprocals[ind] if append: self.configs = np.vstack((self.configs, reciprocals)) return reciprocals
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'gen_configs_permutate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'injections_raw'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'only_same_dipole_length'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ignore_crossed_dipoles'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'silent'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '30', '38', '42', '220', '224', '274', '281']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'injections'}, {'id': '19', 'type': 'call', 'children': ['20', '28']}; {'id': '20', 'type': 'attribute', 'children': ['21', '27']}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'atleast_2d'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'injections_raw'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '33', 'type': 'subscript', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'injections'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'measurements'}, {'id': '41', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '49']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'injection'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '49', 'type': 'block', 'children': ['50', '69']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'dipole_length'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '64'], 'value': '-'}, {'id': '59', 'type': 'subscript', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'injections'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'injection'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'subscript', 'children': ['65', '68']}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'injections'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'injection'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '69', 'type': 'for_statement', 'children': ['70', '71', '85']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '71', 'type': 'binary_operator', 'children': ['72', '80'], 'value': '-'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'list', 'children': ['84'], 'value': '[injection]'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'injection'}, {'id': '85', 'type': 'block', 'children': ['86', '109', '118', '141']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'test_dipole_length'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '102'], 'value': '-'}, {'id': '95', 'type': 'subscript', 'children': ['96', '101']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98', '99']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'injections'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '99', 'type': 'slice', 'children': ['100']}; {'id': '100', 'type': 'colon', 'children': []}, {'id': '101', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '102', 'type': 'subscript', 'children': ['103', '108']}, {'id': '103', 'type': 'subscript', 'children': ['104', '105', '106']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'injections'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '106', 'type': 'slice', 'children': ['107']}, {'id': '107', 'type': 'colon', 'children': []}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '116']}; {'id': '110', 'type': 'parenthesized_expression', 'children': ['111'], 'value': '()'}, {'id': '111', 'type': 'boolean_operator', 'children': ['112', '113'], 'value': 'and'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'only_same_dipole_length'}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '!='}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'test_dipole_length'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'dipole_length'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'continue_statement', 'children': []}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'quadpole'}, {'id': '121', 'type': 'call', 'children': ['122', '140']}; {'id': '122', 'type': 'attribute', 'children': ['123', '139']}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'list', 'children': ['129', '134'], 'value': '[injections[injection, :], injections[i, :]]'}, {'id': '129', 'type': 'subscript', 'children': ['130', '131', '132']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'injections'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'injection'}; {'id': '132', 'type': 'slice', 'children': ['133']}, {'id': '133', 'type': 'colon', 'children': []}; {'id': '134', 'type': 'subscript', 'children': ['135', '136', '137']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'injections'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '137', 'type': 'slice', 'children': ['138']}; {'id': '138', 'type': 'colon', 'children': []}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '140', 'type': 'argument_list', 'children': []}, {'id': '141', 'type': 'if_statement', 'children': ['142', '145', '211']}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'is'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ignore_crossed_dipoles'}; {'id': '144', 'type': 'True', 'children': []}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'if_statement', 'children': ['147', '163', '174', '202']}, {'id': '147', 'type': 'parenthesized_expression', 'children': ['148'], 'value': '()'}; {'id': '148', 'type': 'boolean_operator', 'children': ['149', '156'], 'value': 'and'}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '153'], 'value': '>'}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'quadpole'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '160'], 'value': '<'}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'quadpole'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'if_statement', 'children': ['165', '167']}, {'id': '165', 'type': 'not_operator', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'silent'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'string', 'children': [], 'value': "'A - ignoring'"}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '174', 'type': 'elif_clause', 'children': ['175', '191']}, {'id': '175', 'type': 'parenthesized_expression', 'children': ['176'], 'value': '()'}; {'id': '176', 'type': 'boolean_operator', 'children': ['177', '184'], 'value': 'and'}, {'id': '177', 'type': 'comparison_operator', 'children': ['178', '181'], 'value': '>'}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '180', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '181', 'type': 'subscript', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'quadpole'}, {'id': '183', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '184', 'type': 'comparison_operator', 'children': ['185', '188'], 'value': '<'}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'quadpole'}, {'id': '187', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '190', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '191', 'type': 'block', 'children': ['192']}; {'id': '192', 'type': 'if_statement', 'children': ['193', '195']}, {'id': '193', 'type': 'not_operator', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'silent'}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '199', 'type': 'argument_list', 'children': ['200', '201']}; {'id': '200', 'type': 'string', 'children': [], 'value': "'B - ignoring'"}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '202', 'type': 'else_clause', 'children': ['203']}, {'id': '203', 'type': 'block', 'children': ['204']}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'measurements'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'quadpole'}, {'id': '211', 'type': 'else_clause', 'children': ['212']}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'measurements'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'filtered'}, {'id': '223', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '224', 'type': 'for_statement', 'children': ['225', '226', '227']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'measurements'}, {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'if_statement', 'children': ['229', '253', '265']}, {'id': '229', 'type': 'parenthesized_expression', 'children': ['230'], 'value': '()'}; {'id': '230', 'type': 'not_operator', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '243']}; {'id': '232', 'type': 'attribute', 'children': ['233', '242']}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '238', 'type': 'slice', 'children': ['239', '240', '241']}, {'id': '239', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '240', 'type': 'colon', 'children': []}, {'id': '241', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'isdisjoint'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'subscript', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'quadpole'}, {'id': '249', 'type': 'slice', 'children': ['250', '251', '252']}; {'id': '250', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '251', 'type': 'colon', 'children': []}; {'id': '252', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '253', 'type': 'block', 'children': ['254']}; {'id': '254', 'type': 'if_statement', 'children': ['255', '257']}, {'id': '255', 'type': 'not_operator', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'silent'}, {'id': '257', 'type': 'block', 'children': ['258']}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '261', 'type': 'argument_list', 'children': ['262', '263', '264']}; {'id': '262', 'type': 'string', 'children': [], 'value': "'Ignoring quadrupole because of '"}, {'id': '263', 'type': 'string', 'children': [], 'value': "'repeated electrode use:'"}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'quadpole'}, {'id': '265', 'type': 'else_clause', 'children': ['266']}; {'id': '266', 'type': 'block', 'children': ['267']}, {'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': 'filtered'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'quadpole'}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'add_to_configs'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'filtered'}, {'id': '281', 'type': 'return_statement', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '286']}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'filtered'}
def gen_configs_permutate(self, injections_raw, only_same_dipole_length=False, ignore_crossed_dipoles=False, silent=False): injections = np.atleast_2d(injections_raw).astype(int) N = injections.shape[0] measurements = [] for injection in range(0, N): dipole_length = np.abs(injections[injection][1] - injections[injection][0]) for i in set(range(0, N)) - set([injection]): test_dipole_length = np.abs(injections[i, :][1] - injections[i, :][0]) if (only_same_dipole_length and test_dipole_length != dipole_length): continue quadpole = np.array( [injections[injection, :], injections[i, :]]).flatten() if ignore_crossed_dipoles is True: if (quadpole[2] > quadpole[0] and quadpole[2] < quadpole[1]): if not silent: print('A - ignoring', quadpole) elif (quadpole[3] > quadpole[0] and quadpole[3] < quadpole[1]): if not silent: print('B - ignoring', quadpole) else: measurements.append(quadpole) else: measurements.append(quadpole) filtered = [] for quadpole in measurements: if (not set(quadpole[0:2]).isdisjoint(set(quadpole[2:4]))): if not silent: print('Ignoring quadrupole because of ', 'repeated electrode use:', quadpole) else: filtered.append(quadpole) self.add_to_configs(filtered) return np.array(filtered)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_pg_scheme'}, {'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': 'container'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'positions'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '26', '42', '56', '78', '86', '89', '97', '119', '132', '159', '176']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '20']}, {'id': '13', 'type': 'boolean_operator', 'children': ['14', '17'], 'value': 'and'}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'positions'}, {'id': '19', 'type': 'None', 'children': []}; {'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': 'Exception'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'string', 'children': [], 'value': "'electrode positions are required for BERT export'"}; {'id': '26', 'type': 'if_statement', 'children': ['27', '36']}, {'id': '27', 'type': 'boolean_operator', 'children': ['28', '31'], 'value': 'and'}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '35'], 'value': 'is'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'electrodes'}, {'id': '35', 'type': 'None', 'children': []}; {'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': 'Exception'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'string', 'children': [], 'value': "'container does not contain electrode positions'"}; {'id': '42', 'type': 'if_statement', 'children': ['43', '50']}, {'id': '43', 'type': 'boolean_operator', 'children': ['44', '47'], 'value': 'and'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'positions'}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'raise_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'only one of container OR positions must be provided'"}; {'id': '56', 'type': 'if_statement', 'children': ['57', '60', '69']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'container'}, {'id': '59', 'type': 'None', 'children': []}; {'id': '60', 'type': 'block', 'children': ['61']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'elec_positions'}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'container'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'electrodes'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '69', 'type': 'elif_clause', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'positions'}; {'id': '72', 'type': 'None', 'children': []}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'elec_positions'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'positions'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'opt_import'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': '"pybert"'}, {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'requiredFor'}, {'id': '85', 'type': 'string', 'children': [], 'value': '""'}; {'id': '86', 'type': 'import_statement', 'children': ['87']}, {'id': '87', 'type': 'dotted_name', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'pybert'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'pybert'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'DataContainerERT'}; {'id': '96', 'type': 'argument_list', 'children': []}, {'id': '97', 'type': 'for_statement', 'children': ['98', '104', '108']}; {'id': '98', 'type': 'pattern_list', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'nr'}; {'id': '100', 'type': 'tuple_pattern', 'children': ['101', '102', '103']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'elec_positions'}; {'id': '108', 'type': 'block', 'children': ['109']}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'createSensor'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'tuple', 'children': ['116', '117', '118']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'z'}, {'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': 'data'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'resize'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'subscript', 'children': ['126', '131']}; {'id': '126', 'type': 'attribute', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '131', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '132', 'type': 'for_statement', 'children': ['133', '136', '140']}, {'id': '133', 'type': 'pattern_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'string', 'children': [], 'value': '"abmn"'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '148', 'type': 'call', 'children': ['149', '158']}, {'id': '149', 'type': 'attribute', 'children': ['150', '157']}; {'id': '150', 'type': 'subscript', 'children': ['151', '154', '156']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '154', 'type': 'slice', 'children': ['155']}, {'id': '155', 'type': 'colon', 'children': []}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'tolist'}; {'id': '158', 'type': 'argument_list', 'children': []}, {'id': '159', 'type': 'for_statement', 'children': ['160', '161', '162']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '161', 'type': 'string', 'children': [], 'value': '"abmn"'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '170', 'type': 'binary_operator', 'children': ['171', '175'], 'value': '-'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'token'}, {'id': '175', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '176', 'type': 'return_statement', 'children': ['177']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'data'}
def to_pg_scheme(self, container=None, positions=None): if container is None and positions is None: raise Exception('electrode positions are required for BERT export') if container is not None and container.electrodes is None: raise Exception('container does not contain electrode positions') if container is not None and positions is not None: raise Exception( 'only one of container OR positions must be provided') if container is not None: elec_positions = container.electrodes.values elif positions is not None: elec_positions = positions opt_import("pybert", requiredFor="") import pybert data = pybert.DataContainerERT() for nr, (x, y, z) in enumerate(elec_positions): data.createSensor((x, y, z)) data.resize(self.configs.shape[0]) for index, token in enumerate("abmn"): data.set(token, self.configs[:, index].tolist()) for token in "abmn": data.set(token, data(token) - 1) return data
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'try_sending'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'timeout_secs'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_attempts'}; {'id': '8', 'type': 'block', 'children': ['9', '20', '31', '35']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'timeout_secs'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'timeout_secs'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'max_attempts'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'max_attempts'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'retry_count'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'attempts'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '35', 'type': 'while_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '<'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'attempts'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'max_attempts'}, {'id': '39', 'type': 'block', 'children': ['40', '50', '58', '70', '74', '90']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '48']}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '45'], 'value': 'not'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'seq_num'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'return_statement', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'aio'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'Event'}, {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '69']}; {'id': '60', 'type': 'subscript', 'children': ['61', '68']}, {'id': '61', 'type': 'subscript', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'seq_num'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'augmented_assignment', 'children': ['72', '73'], 'value': '+='}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'attempts'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'transport'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '86']}, {'id': '81', 'type': 'attribute', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'transport'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sendto'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'packed_message'}; {'id': '90', 'type': 'try_statement', 'children': ['91', '108']}, {'id': '91', 'type': 'block', 'children': ['92', '107']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'myresult'}, {'id': '95', 'type': 'await', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'aio'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'wait_for'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '106']}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'wait'}, {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'timeout_secs'}, {'id': '107', 'type': 'break_statement', 'children': []}; {'id': '108', 'type': 'except_clause', 'children': ['109', '113']}, {'id': '109', 'type': 'as_pattern', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '111', 'type': 'as_pattern_target', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'inst'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '>='}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'attempts'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'max_attempts'}; {'id': '118', 'type': 'block', 'children': ['119', '158']}, {'id': '119', 'type': 'if_statement', 'children': ['120', '127']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '124'], 'value': 'in'}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'seq_num'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '127', 'type': 'block', 'children': ['128', '140', '149']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'callb'}, {'id': '131', 'type': 'subscript', 'children': ['132', '139']}; {'id': '132', 'type': 'subscript', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'seq_num'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '140', 'type': 'if_statement', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'callb'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'callb'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'None', 'children': []}, {'id': '149', 'type': 'delete_statement', 'children': ['150']}; {'id': '150', 'type': 'parenthesized_expression', 'children': ['151'], 'value': '()'}, {'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': 'message'}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'seq_num'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'unregister'}, {'id': '163', 'type': 'argument_list', 'children': []}
async def try_sending(self,msg,timeout_secs, max_attempts): if timeout_secs is None: timeout_secs = self.timeout if max_attempts is None: max_attempts = self.retry_count attempts = 0 while attempts < max_attempts: if msg.seq_num not in self.message: return event = aio.Event() self.message[msg.seq_num][1]= event attempts += 1 if self.transport: self.transport.sendto(msg.packed_message) try: myresult = await aio.wait_for(event.wait(),timeout_secs) break except Exception as inst: if attempts >= max_attempts: if msg.seq_num in self.message: callb = self.message[msg.seq_num][2] if callb: callb(self, None) del(self.message[msg.seq_num]) self.unregister()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'apply_correction_factors'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'correction_file'}; {'id': '6', 'type': 'block', 'children': ['7', '158', '184', '210', '222', '230', '243', '406']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '15', '34']}; {'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': 'correction_file'}; {'id': '12', 'type': 'tuple', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'corr_data_raw'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'vstack'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'list_comprehension', 'children': ['25', '31']}, {'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': 'loadtxt'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'correction_file'}; {'id': '34', 'type': 'else_clause', 'children': ['35']}, {'id': '35', 'type': 'block', 'children': ['36', '45']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'corr_data_raw'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'loadtxt'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'correction_file'}, {'id': '45', 'type': 'if_statement', 'children': ['46', '53', '138', '151']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '52'], 'value': '=='}, {'id': '47', 'type': 'subscript', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'corr_data_raw'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '51', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '53', 'type': 'block', 'children': ['54', '70', '86', '102', '118']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'A'}, {'id': '57', 'type': 'call', 'children': ['58', '68']}; {'id': '58', 'type': 'attribute', 'children': ['59', '67']}, {'id': '59', 'type': 'parenthesized_expression', 'children': ['60'], 'value': '()'}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '66'], 'value': '/'}, {'id': '61', 'type': 'subscript', 'children': ['62', '63', '65']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'corr_data_raw'}, {'id': '63', 'type': 'slice', 'children': ['64']}; {'id': '64', 'type': 'colon', 'children': []}, {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'float', 'children': [], 'value': '1e4'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'B'}, {'id': '73', 'type': 'call', 'children': ['74', '84']}; {'id': '74', 'type': 'attribute', 'children': ['75', '83']}, {'id': '75', 'type': 'parenthesized_expression', 'children': ['76'], 'value': '()'}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '82'], 'value': '%'}, {'id': '77', 'type': 'subscript', 'children': ['78', '79', '81']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'corr_data_raw'}, {'id': '79', 'type': 'slice', 'children': ['80']}; {'id': '80', 'type': 'colon', 'children': []}, {'id': '81', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '82', 'type': 'float', 'children': [], 'value': '1e4'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'M'}, {'id': '89', 'type': 'call', 'children': ['90', '100']}; {'id': '90', 'type': 'attribute', 'children': ['91', '99']}, {'id': '91', 'type': 'parenthesized_expression', 'children': ['92'], 'value': '()'}; {'id': '92', 'type': 'binary_operator', 'children': ['93', '98'], 'value': '/'}, {'id': '93', 'type': 'subscript', 'children': ['94', '95', '97']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'corr_data_raw'}, {'id': '95', 'type': 'slice', 'children': ['96']}; {'id': '96', 'type': 'colon', 'children': []}, {'id': '97', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '98', 'type': 'float', 'children': [], 'value': '1e4'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '105', 'type': 'call', 'children': ['106', '116']}; {'id': '106', 'type': 'attribute', 'children': ['107', '115']}, {'id': '107', 'type': 'parenthesized_expression', 'children': ['108'], 'value': '()'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '114'], 'value': '%'}, {'id': '109', 'type': 'subscript', 'children': ['110', '111', '113']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'corr_data_raw'}, {'id': '111', 'type': 'slice', 'children': ['112']}; {'id': '112', 'type': 'colon', 'children': []}, {'id': '113', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '114', 'type': 'float', 'children': [], 'value': '1e4'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'corr_data'}, {'id': '121', 'type': 'attribute', 'children': ['122', '137']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'vstack'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'tuple', 'children': ['128', '129', '130', '131', '132']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'A'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'B'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'M'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '132', 'type': 'subscript', 'children': ['133', '134', '136']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'corr_data_raw'}; {'id': '134', 'type': 'slice', 'children': ['135']}, {'id': '135', 'type': 'colon', 'children': []}; {'id': '136', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '138', 'type': 'elif_clause', 'children': ['139', '146']}, {'id': '139', 'type': 'comparison_operator', 'children': ['140', '145'], 'value': '=='}; {'id': '140', 'type': 'subscript', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'corr_data_raw'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'corr_data'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'corr_data_raw'}, {'id': '151', 'type': 'else_clause', 'children': ['152']}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'raise_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'string', 'children': [], 'value': "'error'"}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '168']}; {'id': '160', 'type': 'subscript', 'children': ['161', '162', '164']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'corr_data'}; {'id': '162', 'type': 'slice', 'children': ['163']}, {'id': '163', 'type': 'colon', 'children': []}; {'id': '164', 'type': 'slice', 'children': ['165', '166', '167']}, {'id': '165', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '166', 'type': 'colon', 'children': []}, {'id': '167', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '181']}, {'id': '173', 'type': 'subscript', 'children': ['174', '175', '177']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'corr_data'}, {'id': '175', 'type': 'slice', 'children': ['176']}; {'id': '176', 'type': 'colon', 'children': []}, {'id': '177', 'type': 'slice', 'children': ['178', '179', '180']}; {'id': '178', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '179', 'type': 'colon', 'children': []}; {'id': '180', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '183', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'assignment', 'children': ['186', '194']}; {'id': '186', 'type': 'subscript', 'children': ['187', '188', '190']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'corr_data'}; {'id': '188', 'type': 'slice', 'children': ['189']}, {'id': '189', 'type': 'colon', 'children': []}; {'id': '190', 'type': 'slice', 'children': ['191', '192', '193']}, {'id': '191', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '192', 'type': 'colon', 'children': []}, {'id': '193', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '207']}, {'id': '199', 'type': 'subscript', 'children': ['200', '201', '203']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'corr_data'}, {'id': '201', 'type': 'slice', 'children': ['202']}; {'id': '202', 'type': 'colon', 'children': []}, {'id': '203', 'type': 'slice', 'children': ['204', '205', '206']}; {'id': '204', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '205', 'type': 'colon', 'children': []}; {'id': '206', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '209', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '210', 'type': 'if_statement', 'children': ['211', '216']}, {'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': 'not'}; {'id': '212', 'type': 'string', 'children': [], 'value': "'frequency'"}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '216', 'type': 'block', 'children': ['217']}, {'id': '217', 'type': 'raise_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'string', 'children': [], 'value': "'No frequency data found. Are you sure this is a seit data set?'"}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'reset_index'}, {'id': '229', 'type': 'argument_list', 'children': []}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'gf'}, {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'groupby'}, {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'list', 'children': ['239', '240', '241', '242'], 'value': "['a', 'b', 'm', 'n']"}, {'id': '239', 'type': 'string', 'children': [], 'value': "'a'"}; {'id': '240', 'type': 'string', 'children': [], 'value': "'b'"}, {'id': '241', 'type': 'string', 'children': [], 'value': "'m'"}; {'id': '242', 'type': 'string', 'children': [], 'value': "'n'"}, {'id': '243', 'type': 'for_statement', 'children': ['244', '247', '254']}; {'id': '244', 'type': 'pattern_list', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'item'}, {'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': 'gf'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '253', 'type': 'argument_list', 'children': []}; {'id': '254', 'type': 'block', 'children': ['255', '286', '339', '366', '373', '397']}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'item_norm'}; {'id': '258', 'type': 'call', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'hstack'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'tuple', 'children': ['264', '275']}; {'id': '264', 'type': 'call', 'children': ['265', '268']}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'subscript', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '271', 'type': 'slice', 'children': ['272', '273', '274']}; {'id': '272', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '273', 'type': 'colon', 'children': []}; {'id': '274', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '282', 'type': 'slice', 'children': ['283', '284', '285']}, {'id': '283', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '284', 'type': 'colon', 'children': []}, {'id': '285', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '289', 'type': 'subscript', 'children': ['290', '338']}; {'id': '290', 'type': 'call', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'binary_operator', 'children': ['296', '328'], 'value': '&'}; {'id': '296', 'type': 'binary_operator', 'children': ['297', '318'], 'value': '&'}, {'id': '297', 'type': 'binary_operator', 'children': ['298', '308'], 'value': '&'}; {'id': '298', 'type': 'parenthesized_expression', 'children': ['299'], 'value': '()'}, {'id': '299', 'type': 'comparison_operator', 'children': ['300', '305'], 'value': '=='}; {'id': '300', 'type': 'subscript', 'children': ['301', '302', '304']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'corr_data'}; {'id': '302', 'type': 'slice', 'children': ['303']}, {'id': '303', 'type': 'colon', 'children': []}; {'id': '304', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '305', 'type': 'subscript', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'item_norm'}, {'id': '307', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '308', 'type': 'parenthesized_expression', 'children': ['309'], 'value': '()'}, {'id': '309', 'type': 'comparison_operator', 'children': ['310', '315'], 'value': '=='}; {'id': '310', 'type': 'subscript', 'children': ['311', '312', '314']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'corr_data'}; {'id': '312', 'type': 'slice', 'children': ['313']}, {'id': '313', 'type': 'colon', 'children': []}; {'id': '314', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '315', 'type': 'subscript', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'item_norm'}, {'id': '317', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '318', 'type': 'parenthesized_expression', 'children': ['319'], 'value': '()'}, {'id': '319', 'type': 'comparison_operator', 'children': ['320', '325'], 'value': '=='}; {'id': '320', 'type': 'subscript', 'children': ['321', '322', '324']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'corr_data'}; {'id': '322', 'type': 'slice', 'children': ['323']}, {'id': '323', 'type': 'colon', 'children': []}; {'id': '324', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '325', 'type': 'subscript', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'item_norm'}, {'id': '327', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '328', 'type': 'parenthesized_expression', 'children': ['329'], 'value': '()'}, {'id': '329', 'type': 'comparison_operator', 'children': ['330', '335'], 'value': '=='}; {'id': '330', 'type': 'subscript', 'children': ['331', '332', '334']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'corr_data'}; {'id': '332', 'type': 'slice', 'children': ['333']}, {'id': '333', 'type': 'colon', 'children': []}; {'id': '334', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '335', 'type': 'subscript', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'item_norm'}, {'id': '337', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '338', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '339', 'type': 'if_statement', 'children': ['340', '346']}; {'id': '340', 'type': 'comparison_operator', 'children': ['341', '345'], 'value': '=='}, {'id': '341', 'type': 'call', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '343', 'type': 'argument_list', 'children': ['344']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '345', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '346', 'type': 'block', 'children': ['347', '352', '355', '361']}, {'id': '347', 'type': 'expression_statement', 'children': ['348']}; {'id': '348', 'type': 'call', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '350', 'type': 'argument_list', 'children': ['351']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '352', 'type': 'import_statement', 'children': ['353']}, {'id': '353', 'type': 'dotted_name', 'children': ['354']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'IPython'}, {'id': '355', 'type': 'expression_statement', 'children': ['356']}; {'id': '356', 'type': 'call', 'children': ['357', '360']}, {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'IPython'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'embed'}; {'id': '360', 'type': 'argument_list', 'children': []}, {'id': '361', 'type': 'raise_statement', 'children': ['362']}; {'id': '362', 'type': 'call', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}, {'id': '365', 'type': 'string', 'children': [], 'value': "'No correction factor found for this configuration'"}; {'id': '366', 'type': 'expression_statement', 'children': ['367']}, {'id': '367', 'type': 'assignment', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'factor'}, {'id': '369', 'type': 'subscript', 'children': ['370', '371', '372']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'corr_data'}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '372', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '373', 'type': 'for_statement', 'children': ['374', '375', '380']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '375', 'type': 'tuple', 'children': ['376', '377', '378', '379']}; {'id': '376', 'type': 'string', 'children': [], 'value': "'r'"}, {'id': '377', 'type': 'string', 'children': [], 'value': "'Zt'"}; {'id': '378', 'type': 'string', 'children': [], 'value': "'Vmn'"}, {'id': '379', 'type': 'string', 'children': [], 'value': "'rho_a'"}; {'id': '380', 'type': 'block', 'children': ['381']}, {'id': '381', 'type': 'if_statement', 'children': ['382', '387']}; {'id': '382', 'type': 'comparison_operator', 'children': ['383', '384'], 'value': 'in'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '384', 'type': 'attribute', 'children': ['385', '386']}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '387', 'type': 'block', 'children': ['388']}; {'id': '388', 'type': 'expression_statement', 'children': ['389']}, {'id': '389', 'type': 'augmented_assignment', 'children': ['390', '396'], 'value': '*='}; {'id': '390', 'type': 'subscript', 'children': ['391', '394', '395']}, {'id': '391', 'type': 'attribute', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'ix'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'factor'}, {'id': '397', 'type': 'expression_statement', 'children': ['398']}; {'id': '398', 'type': 'assignment', 'children': ['399', '405']}, {'id': '399', 'type': 'subscript', 'children': ['400', '403', '404']}; {'id': '400', 'type': 'attribute', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'ix'}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '404', 'type': 'string', 'children': [], 'value': "'corr_fac'"}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'factor'}; {'id': '406', 'type': 'return_statement', 'children': ['407']}, {'id': '407', 'type': 'expression_list', 'children': ['408', '409']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'corr_data'}
def apply_correction_factors(df, correction_file): if isinstance(correction_file, (list, tuple)): corr_data_raw = np.vstack( [np.loadtxt(x) for x in correction_file] ) else: corr_data_raw = np.loadtxt(correction_file) if corr_data_raw.shape[1] == 3: A = (corr_data_raw[:, 0] / 1e4).astype(int) B = (corr_data_raw[:, 0] % 1e4).astype(int) M = (corr_data_raw[:, 1] / 1e4).astype(int) N = (corr_data_raw[:, 1] % 1e4).astype(int) corr_data = np.vstack((A, B, M, N, corr_data_raw[:, 2])).T elif corr_data_raw.shape[1] == 5: corr_data = corr_data_raw else: raise Exception('error') corr_data[:, 0:2] = np.sort(corr_data[:, 0:2], axis=1) corr_data[:, 2:4] = np.sort(corr_data[:, 2:4], axis=1) if 'frequency' not in df.columns: raise Exception( 'No frequency data found. Are you sure this is a seit data set?' ) df = df.reset_index() gf = df.groupby(['a', 'b', 'm', 'n']) for key, item in gf.indices.items(): item_norm = np.hstack((np.sort(key[0:2]), np.sort(key[2:4]))) index = np.where( (corr_data[:, 0] == item_norm[0]) & (corr_data[:, 1] == item_norm[1]) & (corr_data[:, 2] == item_norm[2]) & (corr_data[:, 3] == item_norm[3]) )[0] if len(index) == 0: print(key) import IPython IPython.embed() raise Exception( 'No correction factor found for this configuration' ) factor = corr_data[index, 4] for col in ('r', 'Zt', 'Vmn', 'rho_a'): if col in df.columns: df.ix[item, col] *= factor df.ix[item, 'corr_fac'] = factor return df, corr_data
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'alter_zero_tip_allowed_states'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '22', '62']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'zero_parent2tips'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'allowed_state_feature'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'get_personalized_feature_name'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ALLOWED_STATES'}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '25']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': '=='}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dist'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '32', 'type': 'block', 'children': ['33', '42']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40', '41']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'if_statement', 'children': ['43', '50']}, {'id': '43', 'type': 'boolean_operator', 'children': ['44', '47'], 'value': 'and'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '!='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '49', 'type': 'string', 'children': [], 'value': "''"}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '60']}, {'id': '53', 'type': 'attribute', 'children': ['54', '59']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'zero_parent2tips'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'up'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '62', 'type': 'for_statement', 'children': ['63', '66', '71']}, {'id': '63', 'type': 'pattern_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'zero_tips'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'zero_parent2tips'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'block', 'children': ['72', '76', '107', '120', '124']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'counts'}, {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'for_statement', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'zero_tips'}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'if_statement', 'children': ['81', '84', '97']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'is'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'counts'}, {'id': '83', 'type': 'None', 'children': []}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'counts'}; {'id': '88', 'type': 'call', 'children': ['89', '96']}, {'id': '89', 'type': 'attribute', 'children': ['90', '95']}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'allowed_state_feature'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '96', 'type': 'argument_list', 'children': []}, {'id': '97', 'type': 'else_clause', 'children': ['98']}; {'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': 'counts'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'allowed_state_feature'}, {'id': '107', 'type': 'if_statement', 'children': ['108', '118']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '114'], 'value': '=='}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'counts'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'zero_tips'}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'continue_statement', 'children': []}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'allowed_states'}, {'id': '123', 'type': 'None', 'children': []}; {'id': '124', 'type': 'for_statement', 'children': ['125', '126', '127']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'zero_tips'}, {'id': '127', 'type': 'block', 'children': ['128', '166']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '132', '145']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'allowed_states'}, {'id': '131', 'type': 'None', 'children': []}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'allowed_states'}; {'id': '136', 'type': 'call', 'children': ['137', '144']}, {'id': '137', 'type': 'attribute', 'children': ['138', '143']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'allowed_state_feature'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '144', 'type': 'argument_list', 'children': []}, {'id': '145', 'type': 'else_clause', 'children': ['146']}; {'id': '146', 'type': 'block', 'children': ['147', '155']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'tip_allowed_states'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'tip'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'allowed_state_feature'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '165']}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'allowed_states'}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'nonzero'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'tip_allowed_states'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'tip'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'add_feature'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'allowed_state_feature'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'allowed_states'}
def alter_zero_tip_allowed_states(tree, feature): zero_parent2tips = defaultdict(list) allowed_state_feature = get_personalized_feature_name(feature, ALLOWED_STATES) for tip in tree: if tip.dist == 0: state = getattr(tip, feature, None) if state is not None and state != '': zero_parent2tips[tip.up].append(tip) for parent, zero_tips in zero_parent2tips.items(): counts = None for tip in zero_tips: if counts is None: counts = getattr(tip, allowed_state_feature).copy() else: counts += getattr(tip, allowed_state_feature) if counts.max() == len(zero_tips): continue allowed_states = None for tip in zero_tips: if allowed_states is None: allowed_states = getattr(tip, allowed_state_feature).copy() else: tip_allowed_states = getattr(tip, allowed_state_feature) allowed_states[np.nonzero(tip_allowed_states)] = 1 tip.add_feature(allowed_state_feature, allowed_states)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'choose_ancestral_states_mppa'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'force_joint'}, {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '19', '27', '35', '42', '52', '56', '60', '64', '326']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'lh_feature'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_personalized_feature_name'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'LH'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'allowed_state_feature'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_personalized_feature_name'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ALLOWED_STATES'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'joint_state_feature'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_personalized_feature_name'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'JOINT_STATE'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'pattern_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'state2array'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_state2allowed_states'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '51', 'type': 'False', 'children': []}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'num_scenarios'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'unresolved_nodes'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'num_states'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'for_statement', 'children': ['65', '66', '71']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'traverse'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'block', 'children': ['72', '80', '90', '141', '145', '151', '210', '214', '218', '276', '318']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'marginal_likelihoods'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'lh_feature'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'marginal_probs'}, {'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '/'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'marginal_likelihoods'}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'marginal_likelihoods'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '89', 'type': 'argument_list', 'children': []}; {'id': '90', 'type': 'if_statement', 'children': ['91', '92', '130']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'force_joint'}; {'id': '92', 'type': 'block', 'children': ['93', '101', '107']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'joint_index'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'joint_state_feature'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'joint_prob'}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'marginal_probs'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'joint_index'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'marginal_probs'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'hstack'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'tuple', 'children': ['116', '128']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'delete'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'marginal_probs'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'joint_index'}; {'id': '128', 'type': 'list', 'children': ['129'], 'value': '[joint_prob]'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'joint_prob'}; {'id': '130', 'type': 'else_clause', 'children': ['131']}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'marginal_probs'}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'marginal_probs'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'best_k'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'best_correstion'}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'inf'}, {'id': '151', 'type': 'for_statement', 'children': ['152', '153', '160']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '157']}; {'id': '156', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '157', 'type': 'binary_operator', 'children': ['158', '159'], 'value': '+'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '160', 'type': 'block', 'children': ['161', '188', '197']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'correction'}; {'id': '164', 'type': 'binary_operator', 'children': ['165', '187'], 'value': '-'}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'hstack'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'tuple', 'children': ['171', '179']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '-'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '179', 'type': 'binary_operator', 'children': ['180', '186'], 'value': '/'}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'marginal_probs'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'correction'}, {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'correction'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'dot'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'correction'}, {'id': '197', 'type': 'if_statement', 'children': ['198', '201']}; {'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': '<'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'correction'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'best_correstion'}, {'id': '201', 'type': 'block', 'children': ['202', '206']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'best_correstion'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'correction'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'best_k'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'augmented_assignment', 'children': ['212', '213'], 'value': '*='}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'num_scenarios'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'best_k'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'augmented_assignment', 'children': ['216', '217'], 'value': '+='}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'num_states'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'best_k'}; {'id': '218', 'type': 'if_statement', 'children': ['219', '220', '251']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'force_joint'}; {'id': '220', 'type': 'block', 'children': ['221']}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'indices_selected'}; {'id': '224', 'type': 'subscript', 'children': ['225', '248']}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '227', 'type': 'argument_list', 'children': ['228', '232']}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '234', 'type': 'lambda', 'children': ['235', '237']}, {'id': '235', 'type': 'lambda_parameters', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '237', 'type': 'tuple', 'children': ['238', '244']}; {'id': '238', 'type': 'conditional_expression', 'children': ['239', '240', '243'], 'value': 'if'}, {'id': '239', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '240', 'type': 'comparison_operator', 'children': ['241', '242'], 'value': '=='}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'joint_index'}, {'id': '243', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '244', 'type': 'unary_operator', 'children': ['245'], 'value': '-'}, {'id': '245', 'type': 'subscript', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'marginal_likelihoods'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '248', 'type': 'slice', 'children': ['249', '250']}, {'id': '249', 'type': 'colon', 'children': []}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'best_k'}, {'id': '251', 'type': 'else_clause', 'children': ['252']}; {'id': '252', 'type': 'block', 'children': ['253']}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'indices_selected'}; {'id': '256', 'type': 'subscript', 'children': ['257', '273']}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '259', 'type': 'argument_list', 'children': ['260', '264']}; {'id': '260', 'type': 'call', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '266', 'type': 'lambda', 'children': ['267', '269']}, {'id': '267', 'type': 'lambda_parameters', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '269', 'type': 'unary_operator', 'children': ['270'], 'value': '-'}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'marginal_likelihoods'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '273', 'type': 'slice', 'children': ['274', '275']}; {'id': '274', 'type': 'colon', 'children': []}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'best_k'}; {'id': '276', 'type': 'if_statement', 'children': ['277', '280', '289']}, {'id': '277', 'type': 'comparison_operator', 'children': ['278', '279'], 'value': '=='}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'best_k'}, {'id': '279', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '280', 'type': 'block', 'children': ['281']}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'allowed_states'}; {'id': '284', 'type': 'subscript', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'state2array'}; {'id': '286', 'type': 'subscript', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'indices_selected'}; {'id': '288', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '289', 'type': 'else_clause', 'children': ['290']}; {'id': '290', 'type': 'block', 'children': ['291', '308', '314']}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'assignment', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'allowed_states'}; {'id': '294', 'type': 'call', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '298', 'type': 'argument_list', 'children': ['299', '303']}, {'id': '299', 'type': 'call', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '301', 'type': 'argument_list', 'children': ['302']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '303', 'type': 'keyword_argument', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'assignment', 'children': ['310', '313']}; {'id': '310', 'type': 'subscript', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'allowed_states'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'indices_selected'}, {'id': '313', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'augmented_assignment', 'children': ['316', '317'], 'value': '+='}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'unresolved_nodes'}, {'id': '317', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'add_feature'}, {'id': '323', 'type': 'argument_list', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'allowed_state_feature'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'allowed_states'}; {'id': '326', 'type': 'return_statement', 'children': ['327']}, {'id': '327', 'type': 'expression_list', 'children': ['328', '329', '330']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'num_scenarios'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'unresolved_nodes'}
def choose_ancestral_states_mppa(tree, feature, states, force_joint=True): lh_feature = get_personalized_feature_name(feature, LH) allowed_state_feature = get_personalized_feature_name(feature, ALLOWED_STATES) joint_state_feature = get_personalized_feature_name(feature, JOINT_STATE) n = len(states) _, state2array = get_state2allowed_states(states, False) num_scenarios = 1 unresolved_nodes = 0 num_states = 0 for node in tree.traverse(): marginal_likelihoods = getattr(node, lh_feature) marginal_probs = marginal_likelihoods / marginal_likelihoods.sum() if force_joint: joint_index = getattr(node, joint_state_feature) joint_prob = marginal_probs[joint_index] marginal_probs = np.hstack((np.sort(np.delete(marginal_probs, joint_index)), [joint_prob])) else: marginal_probs = np.sort(marginal_probs) best_k = n best_correstion = np.inf for k in range(1, n + 1): correction = np.hstack((np.zeros(n - k), np.ones(k) / k)) - marginal_probs correction = correction.dot(correction) if correction < best_correstion: best_correstion = correction best_k = k num_scenarios *= best_k num_states += best_k if force_joint: indices_selected = sorted(range(n), key=lambda _: (0 if n == joint_index else 1, -marginal_likelihoods[_]))[:best_k] else: indices_selected = sorted(range(n), key=lambda _: -marginal_likelihoods[_])[:best_k] if best_k == 1: allowed_states = state2array[indices_selected[0]] else: allowed_states = np.zeros(len(states), dtype=np.int) allowed_states[indices_selected] = 1 unresolved_nodes += 1 node.add_feature(allowed_state_feature, allowed_states) return num_scenarios, unresolved_nodes, num_states
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '5', 'type': 'block', 'children': ['6', '18', '22', '26', '209']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'fix_string_case'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'utf'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cur_end'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'for_statement', 'children': ['27', '30', '34']}, {'id': '27', 'type': 'pattern_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}; {'id': '34', 'type': 'block', 'children': ['35', '57', '64']}, {'id': '35', 'type': 'try_statement', 'children': ['36', '44', '51']}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '44', 'type': 'except_clause', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'}; {'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': 'uni_pass'}; {'id': '50', 'type': 'False', 'children': []}, {'id': '51', 'type': 'else_clause', 'children': ['52']}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'uni_pass'}; {'id': '56', 'type': 'True', 'children': []}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '60', 'type': 'dictionary', 'children': ['61']}, {'id': '61', 'type': 'pair', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'matched'"}, {'id': '63', 'type': 'False', 'children': []}; {'id': '64', 'type': 'if_statement', 'children': ['65', '67', '81']}, {'id': '65', 'type': 'not_operator', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'uni_pass'}, {'id': '67', 'type': 'block', 'children': ['68', '74']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'cur_end'}, {'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'output'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '81', 'type': 'elif_clause', 'children': ['82', '87']}; {'id': '82', 'type': 'boolean_operator', 'children': ['83', '86'], 'value': 'and'}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '>='}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'cur_end'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'uni_pass'}, {'id': '87', 'type': 'block', 'children': ['88', '96', '190']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'match_non_rule_patterns'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '100', '121']}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '99', 'type': 'string', 'children': [], 'value': '"matched"'}; {'id': '100', 'type': 'block', 'children': ['101', '110']}, {'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': 'output'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '109', 'type': 'string', 'children': [], 'value': '"replaced"'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'cur_end'}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '+'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '120', 'type': 'string', 'children': [], 'value': '"found"'}, {'id': '121', 'type': 'else_clause', 'children': ['122']}; {'id': '122', 'type': 'block', 'children': ['123', '131']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'match_rule_patterns'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '131', 'type': 'if_statement', 'children': ['132', '135']}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '134', 'type': 'string', 'children': [], 'value': '"matched"'}, {'id': '135', 'type': 'block', 'children': ['136', '147', '167']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'cur_end'}, {'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '+'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '146', 'type': 'string', 'children': [], 'value': '"found"'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'replaced'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'process_rules'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '158', '161', '164']}, {'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'rules'}, {'id': '155', 'type': 'subscript', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '157', 'type': 'string', 'children': [], 'value': '"rules"'}; {'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}, {'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'cur_end'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'cur_end'}, {'id': '167', 'type': 'if_statement', 'children': ['168', '171', '179']}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': 'is'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'replaced'}; {'id': '170', 'type': 'None', 'children': []}, {'id': '171', 'type': 'block', 'children': ['172']}; {'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': 'output'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'replaced'}, {'id': '179', 'type': 'else_clause', 'children': ['180']}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '189', 'type': 'string', 'children': [], 'value': '"replaced"'}; {'id': '190', 'type': 'if_statement', 'children': ['191', '195']}, {'id': '191', 'type': 'not_operator', 'children': ['192']}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '194', 'type': 'string', 'children': [], 'value': '"matched"'}, {'id': '195', 'type': 'block', 'children': ['196', '202']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'cur_end'}, {'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '+'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '201', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '209', 'type': 'return_statement', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'string', 'children': [], 'value': "''"}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'output'}
def parse(text): fixed_text = validate.fix_string_case(utf(text)) output = [] cur_end = 0 for cur, i in enumerate(fixed_text): try: i.encode('utf-8') except UnicodeDecodeError: uni_pass = False else: uni_pass = True match = {'matched': False} if not uni_pass: cur_end = cur + 1 output.append(i) elif cur >= cur_end and uni_pass: match = match_non_rule_patterns(fixed_text, cur) if match["matched"]: output.append(match["replaced"]) cur_end = cur + len(match["found"]) else: match = match_rule_patterns(fixed_text, cur) if match["matched"]: cur_end = cur + len(match["found"]) replaced = process_rules(rules = match["rules"], fixed_text = fixed_text, cur = cur, cur_end = cur_end) if replaced is not None: output.append(replaced) else: output.append(match["replaced"]) if not match["matched"]: cur_end = cur + 1 output.append(i) return ''.join(output)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_match'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'cur_end'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '32', '68', '280']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '12', 'type': 'True', 'children': []}, {'id': '13', 'type': 'if_statement', 'children': ['14', '19', '26']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '18'], 'value': '=='}, {'id': '15', 'type': 'subscript', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'prefix'"}, {'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': 'chk'}, {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '-'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'else_clause', 'children': ['27']}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'cur_end'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '41', '56']}, {'id': '33', 'type': 'call', 'children': ['34', '39']}; {'id': '34', 'type': 'attribute', 'children': ['35', '38']}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '37', 'type': 'string', 'children': [], 'value': "'scope'"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'!'"}, {'id': '41', 'type': 'block', 'children': ['42', '52']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'scope'}, {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'scope'"}, {'id': '49', 'type': 'slice', 'children': ['50', '51']}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '51', 'type': 'colon', 'children': []}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'negative'}, {'id': '55', 'type': 'True', 'children': []}; {'id': '56', 'type': 'else_clause', 'children': ['57']}, {'id': '57', 'type': 'block', 'children': ['58', '64']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'scope'}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'scope'"}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'negative'}, {'id': '67', 'type': 'False', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '72', '117', '167', '217']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '=='}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'scope'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'punctuation'"}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'if_statement', 'children': ['74', '112']}; {'id': '74', 'type': 'parenthesized_expression', 'children': ['75'], 'value': '()'}, {'id': '75', 'type': 'not_operator', 'children': ['76']}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '111'], 'value': '^'}, {'id': '77', 'type': 'parenthesized_expression', 'children': ['78'], 'value': '()'}; {'id': '78', 'type': 'boolean_operator', 'children': ['79', '103'], 'value': 'or'}, {'id': '79', 'type': 'boolean_operator', 'children': ['80', '90'], 'value': 'or'}; {'id': '80', 'type': 'parenthesized_expression', 'children': ['81'], 'value': '()'}, {'id': '81', 'type': 'boolean_operator', 'children': ['82', '85'], 'value': 'and'}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '<'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '89'], 'value': '=='}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '89', 'type': 'string', 'children': [], 'value': "'prefix'"}; {'id': '90', 'type': 'parenthesized_expression', 'children': ['91'], 'value': '()'}, {'id': '91', 'type': 'boolean_operator', 'children': ['92', '98'], 'value': 'and'}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '>='}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'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': 'fixed_text'}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '102'], 'value': '=='}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '102', 'type': 'string', 'children': [], 'value': "'suffix'"}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'is_punctuation'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'negative'}; {'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': 'replace'}; {'id': '116', 'type': 'False', 'children': []}, {'id': '117', 'type': 'elif_clause', 'children': ['118', '121']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '=='}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'scope'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'vowel'"}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'if_statement', 'children': ['123', '162']}, {'id': '123', 'type': 'parenthesized_expression', 'children': ['124'], 'value': '()'}; {'id': '124', 'type': 'not_operator', 'children': ['125']}, {'id': '125', 'type': 'binary_operator', 'children': ['126', '161'], 'value': '^'}; {'id': '126', 'type': 'parenthesized_expression', 'children': ['127'], 'value': '()'}, {'id': '127', 'type': 'boolean_operator', 'children': ['128', '153'], 'value': 'and'}; {'id': '128', 'type': 'parenthesized_expression', 'children': ['129'], 'value': '()'}, {'id': '129', 'type': 'boolean_operator', 'children': ['130', '140'], 'value': 'or'}; {'id': '130', 'type': 'parenthesized_expression', 'children': ['131'], 'value': '()'}, {'id': '131', 'type': 'boolean_operator', 'children': ['132', '135'], 'value': 'and'}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': '>='}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '139'], 'value': '=='}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '139', 'type': 'string', 'children': [], 'value': "'prefix'"}; {'id': '140', 'type': 'parenthesized_expression', 'children': ['141'], 'value': '()'}, {'id': '141', 'type': 'boolean_operator', 'children': ['142', '148'], 'value': 'and'}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '<'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'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': 'fixed_text'}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '152'], 'value': '=='}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '151', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '152', 'type': 'string', 'children': [], 'value': "'suffix'"}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'is_vowel'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'negative'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '166', 'type': 'False', 'children': []}, {'id': '167', 'type': 'elif_clause', 'children': ['168', '171']}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': '=='}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'scope'}; {'id': '170', 'type': 'string', 'children': [], 'value': "'consonant'"}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'if_statement', 'children': ['173', '212']}, {'id': '173', 'type': 'parenthesized_expression', 'children': ['174'], 'value': '()'}; {'id': '174', 'type': 'not_operator', 'children': ['175']}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '211'], 'value': '^'}; {'id': '176', 'type': 'parenthesized_expression', 'children': ['177'], 'value': '()'}, {'id': '177', 'type': 'boolean_operator', 'children': ['178', '203'], 'value': 'and'}; {'id': '178', 'type': 'parenthesized_expression', 'children': ['179'], 'value': '()'}, {'id': '179', 'type': 'boolean_operator', 'children': ['180', '190'], 'value': 'or'}; {'id': '180', 'type': 'parenthesized_expression', 'children': ['181'], 'value': '()'}, {'id': '181', 'type': 'boolean_operator', 'children': ['182', '185'], 'value': 'and'}; {'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': '>='}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '185', 'type': 'comparison_operator', 'children': ['186', '189'], 'value': '=='}; {'id': '186', 'type': 'subscript', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '188', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '189', 'type': 'string', 'children': [], 'value': "'prefix'"}; {'id': '190', 'type': 'parenthesized_expression', 'children': ['191'], 'value': '()'}, {'id': '191', 'type': 'boolean_operator', 'children': ['192', '198'], 'value': 'and'}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '<'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}; {'id': '198', 'type': 'comparison_operator', 'children': ['199', '202'], 'value': '=='}, {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '201', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '202', 'type': 'string', 'children': [], 'value': "'suffix'"}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'is_consonant'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'negative'}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '216', 'type': 'False', 'children': []}, {'id': '217', 'type': 'elif_clause', 'children': ['218', '221']}; {'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': '=='}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'scope'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'exact'"}, {'id': '221', 'type': 'block', 'children': ['222', '261']}; {'id': '222', 'type': 'if_statement', 'children': ['223', '228', '244']}, {'id': '223', 'type': 'comparison_operator', 'children': ['224', '227'], 'value': '=='}; {'id': '224', 'type': 'subscript', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '226', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '227', 'type': 'string', 'children': [], 'value': "'prefix'"}; {'id': '228', 'type': 'block', 'children': ['229', '240']}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'exact_start'}; {'id': '232', 'type': 'binary_operator', 'children': ['233', '234'], 'value': '-'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'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': 'match'}, {'id': '239', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}, {'id': '241', 'type': 'assignment', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'exact_end'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '244', 'type': 'else_clause', 'children': ['245']}, {'id': '245', 'type': 'block', 'children': ['246', '250']}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'exact_start'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'cur_end'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'exact_end'}, {'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '+'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'cur_end'}, {'id': '255', 'type': 'call', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'subscript', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '260', 'type': 'string', 'children': [], 'value': "'value'"}, {'id': '261', 'type': 'if_statement', 'children': ['262', '275']}; {'id': '262', 'type': 'not_operator', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'is_exact'}, {'id': '267', 'type': 'argument_list', 'children': ['268', '271', '272', '273', '274']}; {'id': '268', 'type': 'subscript', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '270', 'type': 'string', 'children': [], 'value': "'value'"}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'fixed_text'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'exact_start'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'exact_end'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'negative'}, {'id': '275', 'type': 'block', 'children': ['276']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '279', 'type': 'False', 'children': []}; {'id': '280', 'type': 'return_statement', 'children': ['281']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'replace'}
def process_match(match, fixed_text, cur, cur_end): replace = True if match['type'] == 'prefix': chk = cur - 1 else: chk = cur_end if match['scope'].startswith('!'): scope = match['scope'][1:] negative = True else: scope = match['scope'] negative = False if scope == 'punctuation': if (not ((chk < 0 and match['type'] == 'prefix') or (chk >= len(fixed_text) and match['type'] == 'suffix') or validate.is_punctuation(fixed_text[chk])) ^ negative): replace = False elif scope == 'vowel': if (not (((chk >= 0 and match['type'] == 'prefix') or (chk < len(fixed_text) and match['type'] == 'suffix')) and validate.is_vowel(fixed_text[chk])) ^ negative): replace = False elif scope == 'consonant': if (not (((chk >= 0 and match['type'] == 'prefix') or (chk < len(fixed_text) and match['type'] == 'suffix')) and validate.is_consonant(fixed_text[chk])) ^ negative): replace = False elif scope == 'exact': if match['type'] == 'prefix': exact_start = cur - len(match['value']) exact_end = cur else: exact_start = cur_end exact_end = cur_end + len(match['value']) if not validate.is_exact(match['value'], fixed_text, exact_start, exact_end, negative): replace = False return replace
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'scatter_norrec'}, {'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': 'filename'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'individual'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '22', '26', '30', '63', '74', '90', '142', '292']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'std_diff_labels'}, {'id': '15', 'type': 'dictionary', 'children': ['16', '19']}; {'id': '16', 'type': 'pair', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'rdiff'"}, {'id': '19', 'type': 'pair', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'rpha'"}, {'id': '21', 'type': 'string', 'children': [], 'value': "'rphadiff'"}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'diff_labels'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'std_diff_labels'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'labels_to_use'}, {'id': '29', 'type': 'dictionary', 'children': []}; {'id': '30', 'type': 'for_statement', 'children': ['31', '34', '39']}, {'id': '31', 'type': 'pattern_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'diff_labels'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '56']}, {'id': '41', 'type': 'boolean_operator', 'children': ['42', '49'], 'value': 'and'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'item'}, {'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': 'data'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '62']}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'labels_to_use'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'g_freq'}; {'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': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'string', 'children': [], 'value': "'frequency'"}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'frequencies'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '89']}; {'id': '84', 'type': 'attribute', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'g_freq'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '89', 'type': 'argument_list', 'children': []}; {'id': '90', 'type': 'if_statement', 'children': ['91', '92', '101']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'individual'}; {'id': '92', 'type': 'block', 'children': ['93', '97']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'figures'}; {'id': '96', 'type': 'dictionary', 'children': []}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'axes_all'}; {'id': '100', 'type': 'dictionary', 'children': []}, {'id': '101', 'type': 'else_clause', 'children': ['102']}; {'id': '102', 'type': 'block', 'children': ['103', '114', '121']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'Nx'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'labels_to_use'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'Ny'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'frequencies'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '126']}, {'id': '123', 'type': 'pattern_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'fig'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'plt'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'subplots'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132', '133']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'Ny'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'Nx'}, {'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'figsize'}, {'id': '135', 'type': 'tuple', 'children': ['136', '139']}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '*'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'Nx'}; {'id': '138', 'type': 'float', 'children': [], 'value': '2.5'}, {'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '*'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'Ny'}, {'id': '141', 'type': 'float', 'children': [], 'value': '2.5'}; {'id': '142', 'type': 'for_statement', 'children': ['143', '148', '152']}, {'id': '143', 'type': 'pattern_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '145', 'type': 'tuple_pattern', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'g_freq'}; {'id': '152', 'type': 'block', 'children': ['153', '187', '271']}, {'id': '153', 'type': 'if_statement', 'children': ['154', '155', '177']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'individual'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '161']}; {'id': '158', 'type': 'pattern_list', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'axes_row'}, {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'subplots'}, {'id': '165', 'type': 'argument_list', 'children': ['166', '167', '168']}; {'id': '166', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'figsize'}; {'id': '170', 'type': 'tuple', 'children': ['171', '174']}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '/'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '16'}, {'id': '173', 'type': 'float', 'children': [], 'value': '2.54'}; {'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '/'}, {'id': '175', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '176', 'type': 'float', 'children': [], 'value': '2.54'}, {'id': '177', 'type': 'else_clause', 'children': ['178']}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'axes_row'}; {'id': '182', 'type': 'subscript', 'children': ['183', '184', '185']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '185', 'type': 'slice', 'children': ['186']}; {'id': '186', 'type': 'colon', 'children': []}, {'id': '187', 'type': 'for_statement', 'children': ['188', '193', '204']}; {'id': '188', 'type': 'pattern_list', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'col_nr'}; {'id': '190', 'type': 'tuple_pattern', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'diff_column'}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'labels_to_use'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '203', 'type': 'argument_list', 'children': []}; {'id': '204', 'type': 'block', 'children': ['205', '224', '230', '242', '249', '256']}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '208', 'type': 'subscript', 'children': ['209', '223']}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'where'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'unary_operator', 'children': ['215'], 'value': '~'}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'isnan'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'diff_column'}, {'id': '223', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '227', 'type': 'subscript', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'axes_row'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'col_nr'}; {'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': 'ax'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'scatter'}, {'id': '235', 'type': 'argument_list', 'children': ['236', '239']}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'diff_column'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}, {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'key'}, {'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': 'ax'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'diff_column'}; {'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': 'ax'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'set_title'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'string', 'children': [], 'value': "'N: {}'"}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'call', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '271', 'type': 'if_statement', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'individual'}, {'id': '273', 'type': 'block', 'children': ['274', '280', '286']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'tight_layout'}, {'id': '279', 'type': 'argument_list', 'children': []}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '285']}; {'id': '282', 'type': 'subscript', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'figures'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'assignment', 'children': ['288', '291']}; {'id': '288', 'type': 'subscript', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'axes_all'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'axes_row'}; {'id': '292', 'type': 'if_statement', 'children': ['293', '294', '299']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'individual'}; {'id': '294', 'type': 'block', 'children': ['295']}, {'id': '295', 'type': 'return_statement', 'children': ['296']}; {'id': '296', 'type': 'expression_list', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'figures'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'axes_all'}, {'id': '299', 'type': 'else_clause', 'children': ['300']}; {'id': '300', 'type': 'block', 'children': ['301', '307']}, {'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': 'fig'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'tight_layout'}; {'id': '306', 'type': 'argument_list', 'children': []}, {'id': '307', 'type': 'return_statement', 'children': ['308']}; {'id': '308', 'type': 'expression_list', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'fig'}
def scatter_norrec(self, filename=None, individual=False): std_diff_labels = { 'r': 'rdiff', 'rpha': 'rphadiff', } diff_labels = std_diff_labels labels_to_use = {} for key, item in diff_labels.items(): if key in self.data.columns and item in self.data.columns: labels_to_use[key] = item g_freq = self.data.groupby('frequency') frequencies = list(sorted(g_freq.groups.keys())) if individual: figures = {} axes_all = {} else: Nx = len(labels_to_use.keys()) Ny = len(frequencies) fig, axes = plt.subplots( Ny, Nx, figsize=(Nx * 2.5, Ny * 2.5) ) for row, (name, item) in enumerate(g_freq): if individual: fig, axes_row = plt.subplots( 1, 2, figsize=(16 / 2.54, 6 / 2.54)) else: axes_row = axes[row, :] for col_nr, (key, diff_column) in enumerate( sorted(labels_to_use.items())): indices = np.where(~np.isnan(item[diff_column]))[0] ax = axes_row[col_nr] ax.scatter( item[key], item[diff_column], ) ax.set_xlabel(key) ax.set_ylabel(diff_column) ax.set_title('N: {}'.format(len(indices))) if individual: fig.tight_layout() figures[name] = fig axes_all[name] = axes_row if individual: return figures, axes_all else: fig.tight_layout() return fig, axes
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_spectrum'}, {'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': 'nr_id'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'abmn'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'plot_filename'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '23', '73', '94', '115', '119', '123', '157', '191', '242']}, {'id': '15', 'type': 'assert_statement', 'children': ['16']}; {'id': '16', 'type': 'boolean_operator', 'children': ['17', '20'], 'value': 'or'}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'nr_id'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'abmn'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'abmn'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28', '50', '63']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'subdata'}, {'id': '31', 'type': 'call', 'children': ['32', '48']}; {'id': '32', 'type': 'attribute', 'children': ['33', '47']}, {'id': '33', 'type': 'call', 'children': ['34', '39']}; {'id': '34', 'type': 'attribute', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'a == {} and b == {} and m == {} and n == {}'"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'list_splat', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'abmn'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort_values'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'string', 'children': [], 'value': "'frequency'"}; {'id': '50', 'type': 'if_statement', 'children': ['51', '58']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '57'], 'value': '=='}; {'id': '52', 'type': 'subscript', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'subdata'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'expression_list', 'children': ['61', '62']}, {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'None', 'children': []}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'nr_id'}; {'id': '66', 'type': 'subscript', 'children': ['67', '72']}, {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'id'"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'iloc'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'subdata_nor'}; {'id': '76', 'type': 'call', 'children': ['77', '92']}, {'id': '77', 'type': 'attribute', 'children': ['78', '91']}; {'id': '78', 'type': 'call', 'children': ['79', '84']}, {'id': '79', 'type': 'attribute', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'string', 'children': [], 'value': '\'id == {} and norrec=="nor"\''}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'nr_id'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'sort_values'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'string', 'children': [], 'value': "'frequency'"}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'subdata_rec'}, {'id': '97', 'type': 'call', 'children': ['98', '113']}; {'id': '98', 'type': 'attribute', 'children': ['99', '112']}, {'id': '99', 'type': 'call', 'children': ['100', '105']}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': '\'id == {} and norrec=="rec"\''}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'nr_id'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'sort_values'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'string', 'children': [], 'value': "'frequency'"}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'spectrum_nor'}; {'id': '118', 'type': 'None', 'children': []}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'spectrum_rec'}; {'id': '122', 'type': 'None', 'children': []}, {'id': '123', 'type': 'if_statement', 'children': ['124', '131']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '130'], 'value': '>'}, {'id': '125', 'type': 'subscript', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'subdata_nor'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'spectrum_nor'}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'eis_plot'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'sip_response'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '147', '152']}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '142', 'type': 'attribute', 'children': ['143', '146']}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'subdata_nor'}, {'id': '145', 'type': 'string', 'children': [], 'value': "'frequency'"}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'rmag'}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'subdata_nor'}, {'id': '151', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'rpha'}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'subdata_nor'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'rpha'"}, {'id': '157', 'type': 'if_statement', 'children': ['158', '165']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '164'], 'value': '>'}, {'id': '159', 'type': 'subscript', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'subdata_rec'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '163', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'spectrum_rec'}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'eis_plot'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'sip_response'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '181', '186']}; {'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '176', 'type': 'attribute', 'children': ['177', '180']}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'subdata_rec'}, {'id': '179', 'type': 'string', 'children': [], 'value': "'frequency'"}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'rmag'}, {'id': '183', 'type': 'subscript', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'subdata_rec'}, {'id': '185', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'rpha'}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'subdata_rec'}; {'id': '190', 'type': 'string', 'children': [], 'value': "'rpha'"}, {'id': '191', 'type': 'if_statement', 'children': ['192', '195']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'plot_filename'}; {'id': '194', 'type': 'None', 'children': []}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'if_statement', 'children': ['197', '200']}, {'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': 'is'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'spectrum_nor'}, {'id': '199', 'type': 'None', 'children': []}; {'id': '200', 'type': 'block', 'children': ['201', '237']}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'spectrum_nor'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'plot'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '210', '213', '216']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'plot_filename'}; {'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'reciprocal'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'spectrum_rec'}, {'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'return_fig'}, {'id': '215', 'type': 'True', 'children': []}; {'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'string', 'children': [], 'value': "'a: {} b: {} m: {}: n: {}'"}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'list_splat', 'children': ['224']}; {'id': '224', 'type': 'subscript', 'children': ['225', '234', '235']}, {'id': '225', 'type': 'attribute', 'children': ['226', '233']}; {'id': '226', 'type': 'subscript', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'subdata_nor'}; {'id': '228', 'type': 'list', 'children': ['229', '230', '231', '232'], 'value': "['a', 'b', 'm', 'n']"}, {'id': '229', 'type': 'string', 'children': [], 'value': "'a'"}; {'id': '230', 'type': 'string', 'children': [], 'value': "'b'"}, {'id': '231', 'type': 'string', 'children': [], 'value': "'m'"}; {'id': '232', 'type': 'string', 'children': [], 'value': "'n'"}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '234', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '235', 'type': 'slice', 'children': ['236']}; {'id': '236', 'type': 'colon', 'children': []}, {'id': '237', 'type': 'return_statement', 'children': ['238']}; {'id': '238', 'type': 'expression_list', 'children': ['239', '240', '241']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'spectrum_nor'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'spectrum_rec'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '242', 'type': 'return_statement', 'children': ['243']}, {'id': '243', 'type': 'expression_list', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'spectrum_nor'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'spectrum_rec'}
def get_spectrum(self, nr_id=None, abmn=None, plot_filename=None): assert nr_id is None or abmn is None if abmn is not None: subdata = self.data.query( 'a == {} and b == {} and m == {} and n == {}'.format(*abmn) ).sort_values('frequency') if subdata.shape[0] == 0: return None, None nr_id = subdata['id'].iloc[0] subdata_nor = self.data.query( 'id == {} and norrec=="nor"'.format(nr_id) ).sort_values('frequency') subdata_rec = self.data.query( 'id == {} and norrec=="rec"'.format(nr_id) ).sort_values('frequency') spectrum_nor = None spectrum_rec = None if subdata_nor.shape[0] > 0: spectrum_nor = eis_plot.sip_response( frequencies=subdata_nor['frequency'].values, rmag=subdata_nor['r'], rpha=subdata_nor['rpha'], ) if subdata_rec.shape[0] > 0: spectrum_rec = eis_plot.sip_response( frequencies=subdata_rec['frequency'].values, rmag=subdata_rec['r'], rpha=subdata_rec['rpha'], ) if plot_filename is not None: if spectrum_nor is not None: fig = spectrum_nor.plot( plot_filename, reciprocal=spectrum_rec, return_fig=True, title='a: {} b: {} m: {}: n: {}'.format( *subdata_nor[['a', 'b', 'm', 'n']].values[0, :] ) ) return spectrum_nor, spectrum_rec, fig return spectrum_nor, spectrum_rec
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'import_bin'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '7', 'type': 'block', 'children': ['8', '17', '27', '58', '188', '214', '229', '241', '249', '257', '265', '273', '281', '289', '297', '305', '315', '345']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '13']}; {'id': '10', 'type': 'pattern_list', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'data_raw'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_import_bin'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'skip_rows'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'string', 'children': [], 'value': "'skip_rows'"}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '27', 'type': 'if_statement', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': '>'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'skip_rows'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '31', 'type': 'block', 'children': ['32', '50']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'drop'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '47']}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'data_raw'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'skip_rows'}, {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'inplace'}, {'id': '49', 'type': 'True', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'data_raw'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'reset_index'}, {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'if_statement', 'children': ['59', '66']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'check_meas_nums'"}, {'id': '65', 'type': 'True', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67', '85', '112', '126', '139']}, {'id': '67', 'type': 'if_statement', 'children': ['68', '77']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '76'], 'value': '!='}, {'id': '69', 'type': 'subscript', 'children': ['70', '75']}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'data_raw'}, {'id': '73', 'type': 'string', 'children': [], 'value': "'measurement_num'"}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'iloc'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '+'}, {'id': '83', 'type': 'string', 'children': [], 'value': "'WARNING: Measurement numbers do not start with 0 '"}; {'id': '84', 'type': 'string', 'children': [], 'value': "'(did you download ALL data?)'"}, {'id': '85', 'type': 'if_statement', 'children': ['86', '102']}; {'id': '86', 'type': 'not_operator', 'children': ['87']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '101'], 'value': '=='}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'measurement_num'"}, {'id': '101', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'concatenated_string', 'children': ['108', '109', '110', '111']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'WARNING '"}, {'id': '109', 'type': 'string', 'children': [], 'value': "'Measurement numbers are not consecutive. '"}; {'id': '110', 'type': 'string', 'children': [], 'value': "'Perhaps the first measurement belongs to another measurement?'"}, {'id': '111', 'type': 'string', 'children': [], 'value': "' Use the skip_rows parameter to skip those measurements'"}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '115', 'type': 'subscript', 'children': ['116', '123']}; {'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': 'data_raw'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'measurement_num'"}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '122', 'type': 'argument_list', 'children': []}, {'id': '123', 'type': 'slice', 'children': ['124', '125']}; {'id': '124', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '125', 'type': 'colon', 'children': []}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'jump'}, {'id': '129', 'type': 'subscript', 'children': ['130', '138']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': '!='}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '139', 'type': 'if_statement', 'children': ['140', '146']}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '145'], 'value': '>'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'jump'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '146', 'type': 'block', 'children': ['147', '152', '157', '166', '171']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'string', 'children': [], 'value': "'WARNING: One or more jumps in measurement numbers detected'"}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'string', 'children': [], 'value': "'The jump indices are:'"}, {'id': '157', 'type': 'for_statement', 'children': ['158', '159', '160']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'jump_nr'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'jump'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'jump_nr'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'string', 'children': [], 'value': "'Removing data points subsequent to the first jump'"}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '174', 'type': 'subscript', 'children': ['175', '178', '186']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'data_raw'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'iloc'}; {'id': '178', 'type': 'slice', 'children': ['179', '180', '181']}, {'id': '179', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '180', 'type': 'colon', 'children': []}, {'id': '181', 'type': 'binary_operator', 'children': ['182', '185'], 'value': '+'}; {'id': '182', 'type': 'subscript', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'jump'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '185', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '186', 'type': 'slice', 'children': ['187']}, {'id': '187', 'type': 'colon', 'children': []}; {'id': '188', 'type': 'if_statement', 'children': ['189', '196']}, {'id': '189', 'type': 'comparison_operator', 'children': ['190', '195'], 'value': '=='}; {'id': '190', 'type': 'subscript', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'data_raw'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '194', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '195', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '196', 'type': 'block', 'children': ['197']}, {'id': '197', 'type': 'return_statement', 'children': ['198']}; {'id': '198', 'type': 'expression_list', 'children': ['199', '212', '213']}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '206', 'type': 'list', 'children': ['207', '208', '209', '210', '211'], 'value': "['a', 'b', 'm', 'n', 'r']"}, {'id': '207', 'type': 'string', 'children': [], 'value': "'a'"}; {'id': '208', 'type': 'string', 'children': [], 'value': "'b'"}, {'id': '209', 'type': 'string', 'children': [], 'value': "'m'"}; {'id': '210', 'type': 'string', 'children': [], 'value': "'n'"}, {'id': '211', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '212', 'type': 'None', 'children': []}, {'id': '213', 'type': 'None', 'children': []}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': '_convert_coords_to_abmn_X'}, {'id': '219', 'type': 'argument_list', 'children': ['220', '227']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '222', 'type': 'list', 'children': ['223', '224', '225', '226'], 'value': "['x_a', 'x_b', 'x_m', 'x_n']"}, {'id': '223', 'type': 'string', 'children': [], 'value': "'x_a'"}; {'id': '224', 'type': 'string', 'children': [], 'value': "'x_b'"}, {'id': '225', 'type': 'string', 'children': [], 'value': "'x_m'"}; {'id': '226', 'type': 'string', 'children': [], 'value': "'x_n'"}, {'id': '227', 'type': 'dictionary_splat', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '234']}, {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '233', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '234', 'type': 'binary_operator', 'children': ['235', '238'], 'value': '/'}, {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'data_raw'}, {'id': '237', 'type': 'string', 'children': [], 'value': "'vp'"}; {'id': '238', 'type': 'subscript', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '240', 'type': 'string', 'children': [], 'value': "'Iab'"}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '246']}, {'id': '243', 'type': 'subscript', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '245', 'type': 'string', 'children': [], 'value': "'Vmn'"}; {'id': '246', 'type': 'subscript', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '248', 'type': 'string', 'children': [], 'value': "'vp'"}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '254']}, {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '253', 'type': 'string', 'children': [], 'value': "'vab'"}; {'id': '254', 'type': 'subscript', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '256', 'type': 'string', 'children': [], 'value': "'vab'"}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '262']}, {'id': '259', 'type': 'subscript', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '261', 'type': 'string', 'children': [], 'value': "'Iab'"}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '264', 'type': 'string', 'children': [], 'value': "'Iab'"}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '270']}, {'id': '267', 'type': 'subscript', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '269', 'type': 'string', 'children': [], 'value': "'mdelay'"}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '272', 'type': 'string', 'children': [], 'value': "'mdelay'"}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '278']}, {'id': '275', 'type': 'subscript', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '277', 'type': 'string', 'children': [], 'value': "'Tm'"}; {'id': '278', 'type': 'subscript', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '280', 'type': 'string', 'children': [], 'value': "'Tm'"}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '286']}, {'id': '283', 'type': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '285', 'type': 'string', 'children': [], 'value': "'Mx'"}; {'id': '286', 'type': 'subscript', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '288', 'type': 'string', 'children': [], 'value': "'Mx'"}, {'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': 'data'}, {'id': '293', 'type': 'string', 'children': [], 'value': "'chargeability'"}; {'id': '294', 'type': 'subscript', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '296', 'type': 'string', 'children': [], 'value': "'m'"}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '302']}, {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '301', 'type': 'string', 'children': [], 'value': "'q'"}; {'id': '302', 'type': 'subscript', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'data_raw'}; {'id': '304', 'type': 'string', 'children': [], 'value': "'q'"}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'rec_max'}; {'id': '308', 'type': 'call', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '312', 'type': 'argument_list', 'children': ['313', '314']}, {'id': '313', 'type': 'string', 'children': [], 'value': "'reciprocals'"}; {'id': '314', 'type': 'None', 'children': []}, {'id': '315', 'type': 'if_statement', 'children': ['316', '319']}; {'id': '316', 'type': 'comparison_operator', 'children': ['317', '318'], 'value': 'is'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'rec_max'}; {'id': '318', 'type': 'None', 'children': []}, {'id': '319', 'type': 'block', 'children': ['320', '325']}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'call', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'string', 'children': [], 'value': "'renumbering electrode numbers'"}, {'id': '325', 'type': 'expression_statement', 'children': ['326']}; {'id': '326', 'type': 'assignment', 'children': ['327', '334']}, {'id': '327', 'type': 'subscript', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '329', 'type': 'list', 'children': ['330', '331', '332', '333'], 'value': "['a', 'b', 'm', 'n']"}; {'id': '330', 'type': 'string', 'children': [], 'value': "'a'"}, {'id': '331', 'type': 'string', 'children': [], 'value': "'b'"}; {'id': '332', 'type': 'string', 'children': [], 'value': "'m'"}, {'id': '333', 'type': 'string', 'children': [], 'value': "'n'"}; {'id': '334', 'type': 'binary_operator', 'children': ['335', '338'], 'value': '-'}, {'id': '335', 'type': 'binary_operator', 'children': ['336', '337'], 'value': '+'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'rec_max'}, {'id': '337', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '338', 'type': 'subscript', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '340', 'type': 'list', 'children': ['341', '342', '343', '344'], 'value': "['a', 'b', 'm', 'n']"}, {'id': '341', 'type': 'string', 'children': [], 'value': "'a'"}; {'id': '342', 'type': 'string', 'children': [], 'value': "'b'"}, {'id': '343', 'type': 'string', 'children': [], 'value': "'m'"}; {'id': '344', 'type': 'string', 'children': [], 'value': "'n'"}, {'id': '345', 'type': 'return_statement', 'children': ['346']}; {'id': '346', 'type': 'expression_list', 'children': ['347', '348', '349']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '348', 'type': 'None', 'children': []}, {'id': '349', 'type': 'None', 'children': []}
def import_bin(filename, **kwargs): metadata, data_raw = _import_bin(filename) skip_rows = kwargs.get('skip_rows', 0) if skip_rows > 0: data_raw.drop(data_raw.index[range(0, skip_rows)], inplace=True) data_raw = data_raw.reset_index() if kwargs.get('check_meas_nums', True): if data_raw['measurement_num'].iloc[0] != 0: print('WARNING: Measurement numbers do not start with 0 ' + '(did you download ALL data?)') if not np.all(np.diff(data_raw['measurement_num'])) == 1: print( 'WARNING ' 'Measurement numbers are not consecutive. ' 'Perhaps the first measurement belongs to another measurement?' ' Use the skip_rows parameter to skip those measurements' ) diff = data_raw['measurement_num'].diff()[1:] jump = np.where(diff != 1)[0] if len(jump) > 0: print('WARNING: One or more jumps in measurement numbers detected') print('The jump indices are:') for jump_nr in jump: print(jump_nr) print('Removing data points subsequent to the first jump') data_raw = data_raw.iloc[0:jump[0] + 1, :] if data_raw.shape[0] == 0: return pd.DataFrame(columns=['a', 'b', 'm', 'n', 'r']), None, None data = _convert_coords_to_abmn_X( data_raw[['x_a', 'x_b', 'x_m', 'x_n']], **kwargs ) data['r'] = data_raw['vp'] / data_raw['Iab'] data['Vmn'] = data_raw['vp'] data['vab'] = data_raw['vab'] data['Iab'] = data_raw['Iab'] data['mdelay'] = data_raw['mdelay'] data['Tm'] = data_raw['Tm'] data['Mx'] = data_raw['Mx'] data['chargeability'] = data_raw['m'] data['q'] = data_raw['q'] rec_max = kwargs.get('reciprocals', None) if rec_max is not None: print('renumbering electrode numbers') data[['a', 'b', 'm', 'n']] = rec_max + 1 - data[['a', 'b', 'm', 'n']] return data, None, None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '43']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'datoms'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'aevt'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '10', 'type': 'string', 'children': [], 'value': "''"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '13', 'type': 'string', 'children': [], 'value': "''"}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '16', 'type': 'string', 'children': [], 'value': "''"}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'chunk'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '28', 'type': 'string', 'children': [], 'value': "''"}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '31', 'type': 'string', 'children': [], 'value': "''"}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'since'}; {'id': '34', 'type': 'string', 'children': [], 'value': "''"}, {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'as_of'}, {'id': '37', 'type': 'string', 'children': [], 'value': "''"}; {'id': '38', 'type': 'default_parameter', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'history'}; {'id': '40', 'type': 'string', 'children': [], 'value': "''"}, {'id': '41', 'type': 'dictionary_splat_pattern', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '43', 'type': 'block', 'children': ['44', '53', '127', '135', '139']}; {'id': '44', 'type': 'assert_statement', 'children': ['45', '52']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '47', 'type': 'list', 'children': ['48', '49', '50', '51'], 'value': "['aevt','eavt','avet','vaet']"}; {'id': '48', 'type': 'string', 'children': [], 'value': "'aevt'"}, {'id': '49', 'type': 'string', 'children': [], 'value': "'eavt'"}; {'id': '50', 'type': 'string', 'children': [], 'value': "'avet'"}, {'id': '51', 'type': 'string', 'children': [], 'value': "'vaet'"}; {'id': '52', 'type': 'string', 'children': [], 'value': '"non-existant index"'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '56', 'type': 'dictionary', 'children': ['57', '60', '71', '80', '89', '94', '97', '100', '103', '109', '118']}, {'id': '57', 'type': 'pair', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'index'"}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '60', 'type': 'pair', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'a'"}; {'id': '62', 'type': 'conditional_expression', 'children': ['63', '69', '70'], 'value': 'if'}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': "':{0}'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '70', 'type': 'string', 'children': [], 'value': "''"}, {'id': '71', 'type': 'pair', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'v'"}, {'id': '73', 'type': 'conditional_expression', 'children': ['74', '78', '79'], 'value': 'if'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'dump_edn_val'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '79', 'type': 'string', 'children': [], 'value': "''"}; {'id': '80', 'type': 'pair', 'children': ['81', '82']}, {'id': '81', 'type': 'string', 'children': [], 'value': "'e'"}; {'id': '82', 'type': 'conditional_expression', 'children': ['83', '87', '88'], 'value': 'if'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '88', 'type': 'string', 'children': [], 'value': "''"}, {'id': '89', 'type': 'pair', 'children': ['90', '91']}; {'id': '90', 'type': 'string', 'children': [], 'value': "'offset'"}, {'id': '91', 'type': 'boolean_operator', 'children': ['92', '93'], 'value': 'or'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '94', 'type': 'pair', 'children': ['95', '96']}, {'id': '95', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '97', 'type': 'pair', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'end'"}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '100', 'type': 'pair', 'children': ['101', '102']}, {'id': '101', 'type': 'string', 'children': [], 'value': "'limit'"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '103', 'type': 'pair', 'children': ['104', '105']}; {'id': '104', 'type': 'string', 'children': [], 'value': "'history'"}, {'id': '105', 'type': 'conditional_expression', 'children': ['106', '107', '108'], 'value': 'if'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'true'"}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'history'}; {'id': '108', 'type': 'string', 'children': [], 'value': "''"}, {'id': '109', 'type': 'pair', 'children': ['110', '111']}; {'id': '110', 'type': 'string', 'children': [], 'value': "'as-of'"}, {'id': '111', 'type': 'conditional_expression', 'children': ['112', '116', '117'], 'value': 'if'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'as_of'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'as_of'}, {'id': '117', 'type': 'string', 'children': [], 'value': "''"}; {'id': '118', 'type': 'pair', 'children': ['119', '120']}, {'id': '119', 'type': 'string', 'children': [], 'value': "'since'"}; {'id': '120', 'type': 'conditional_expression', 'children': ['121', '125', '126'], 'value': 'if'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'since'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'since'}; {'id': '126', 'type': 'string', 'children': [], 'value': "''"}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '132']}, {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '131', 'type': 'string', 'children': [], 'value': "'limit'"}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '+'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'chunk'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'rs'}; {'id': '138', 'type': 'True', 'children': []}, {'id': '139', 'type': 'while_statement', 'children': ['140', '151']}; {'id': '140', 'type': 'boolean_operator', 'children': ['141', '142'], 'value': 'and'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'rs'}; {'id': '142', 'type': 'parenthesized_expression', 'children': ['143'], 'value': '()'}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '147'], 'value': '<'}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '146', 'type': 'string', 'children': [], 'value': "'offset'"}, {'id': '147', 'type': 'parenthesized_expression', 'children': ['148'], 'value': '()'}; {'id': '148', 'type': 'boolean_operator', 'children': ['149', '150'], 'value': 'or'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '1000000000'}, {'id': '151', 'type': 'block', 'children': ['152', '162', '182', '193', '205', '225', '232']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ta'}, {'id': '155', 'type': 'call', 'children': ['156', '161']}; {'id': '156', 'type': 'attribute', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '161', 'type': 'argument_list', 'children': []}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'rs'}, {'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': 'rest'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '171', '176', '179']}; {'id': '170', 'type': 'string', 'children': [], 'value': "'GET'"}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '175'], 'value': '+'}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'uri_db'}, {'id': '175', 'type': 'string', 'children': [], 'value': "'-/datoms'"}; {'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '181', 'type': 'True', 'children': []}; {'id': '182', 'type': 'if_statement', 'children': ['183', '188']}, {'id': '183', 'type': 'not_operator', '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': 'rs'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'rs'}; {'id': '192', 'type': 'False', 'children': []}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'tb'}; {'id': '196', 'type': 'binary_operator', 'children': ['197', '204'], 'value': '-'}, {'id': '197', 'type': 'call', 'children': ['198', '203']}; {'id': '198', 'type': 'attribute', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '203', 'type': 'argument_list', 'children': []}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'ta'}, {'id': '205', 'type': 'print_statement', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'cl'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '224']}, {'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '%'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'<<< fetched %i datoms at offset %i in %sms'"}, {'id': '211', 'type': 'tuple', 'children': ['212', '216', '219']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'rs'}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'offset'"}, {'id': '219', 'type': 'binary_operator', 'children': ['220', '223'], 'value': '/'}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'tb'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'microseconds'}, {'id': '223', 'type': 'float', 'children': [], 'value': '1000.0'}; {'id': '224', 'type': 'string', 'children': [], 'value': "'cyan'"}, {'id': '225', 'type': 'for_statement', 'children': ['226', '227', '228']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'rs'}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'yield', 'children': ['231']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'augmented_assignment', 'children': ['234', '237'], 'value': '+='}; {'id': '234', 'type': 'subscript', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'offset'"}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'chunk'}
def datoms(self, index='aevt', e='', a='', v='', limit=0, offset=0, chunk=100, start='', end='', since='', as_of='', history='', **kwargs): assert index in ['aevt','eavt','avet','vaet'], "non-existant index" data = {'index': index, 'a': ':{0}'.format(a) if a else '', 'v': dump_edn_val(v) if v else '', 'e': int(e) if e else '', 'offset': offset or 0, 'start': start, 'end': end, 'limit': limit, 'history': 'true' if history else '', 'as-of': int(as_of) if as_of else '', 'since': int(since) if since else '', } data['limit'] = offset + chunk rs = True while rs and (data['offset'] < (limit or 1000000000)): ta = datetime.datetime.now() rs = self.rest('GET', self.uri_db + '-/datoms', data=data, parse=True) if not len(rs): rs = False tb = datetime.datetime.now() - ta print cl('<<< fetched %i datoms at offset %i in %sms' % ( len(rs), data['offset'], tb.microseconds/1000.0), 'cyan') for r in rs: yield r data['offset'] += chunk
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '17', '30', '147', '149', '172', '174', '203', '205', '367', '369']}; {'id': '10', 'type': 'assert_statement', 'children': ['11', '16']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '15'], 'value': 'is'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'string', 'children': [], 'value': '"Transaction already committed"'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '23']}, {'id': '19', 'type': 'pattern_list', 'children': ['20', '21', '22']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'entity'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'av_pairs'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '23', 'type': 'expression_list', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '35']}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '35', 'type': 'block', 'children': ['36', '122', '124']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '46', '61']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '43']}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '43', 'type': 'tuple', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'long'}; {'id': '46', 'type': 'block', 'children': ['47', '49']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'string', 'children': [], 'value': '" first arg is an entity or tempid"'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '58']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'tx'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'elif_clause', 'children': ['62', '69']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '68']}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'E'}, {'id': '69', 'type': 'block', 'children': ['70', '72']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'string', 'children': [], 'value': '" dont resuse entity from another tx"'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '80', '87']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '79'], 'value': 'is'}; {'id': '74', 'type': 'attribute', 'children': ['75', '78']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_tx'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '87', 'type': 'else_clause', 'children': ['88']}; {'id': '88', 'type': 'block', 'children': ['89', '116']}, {'id': '89', 'type': 'if_statement', 'children': ['90', '98']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '97'], 'value': '>'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '98', 'type': 'block', 'children': ['99', '101']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'string', 'children': [], 'value': '" use the entity id on a new obj"'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '113']}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'tx'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '121']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '121', 'type': 'None', 'children': []}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'string', 'children': [], 'value': '" drop the first arg"'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '137']}, {'id': '125', 'type': 'boolean_operator', 'children': ['126', '129'], 'value': 'or'}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'is'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '128', 'type': 'None', 'children': []}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': 'in'}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '133', 'type': 'tuple', 'children': ['134', '135', '136']}; {'id': '134', 'type': 'None', 'children': []}, {'id': '135', 'type': 'False', 'children': []}; {'id': '136', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'v'}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'string', 'children': [], 'value': '" auto generate a temp id?"'}, {'id': '149', 'type': 'if_statement', 'children': ['150', '153']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': 'is'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '152', 'type': 'None', 'children': []}, {'id': '153', 'type': 'block', 'children': ['154', '166']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'entity'}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'E'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'ctmpid'}, {'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'tx'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'augmented_assignment', 'children': ['168', '171'], 'value': '-='}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ctmpid'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'string', 'children': [], 'value': '" a,v from kwargs"'}; {'id': '174', 'type': 'if_statement', 'children': ['175', '183']}, {'id': '175', 'type': 'boolean_operator', 'children': ['176', '182'], 'value': 'and'}; {'id': '176', 'type': 'comparison_operator', 'children': ['177', '181'], 'value': '=='}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '181', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'for_statement', 'children': ['185', '188', '193']}, {'id': '185', 'type': 'pattern_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '192', 'type': 'argument_list', 'children': []}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'addeav'}, {'id': '199', 'type': 'argument_list', 'children': ['200', '201', '202']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'entity'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'string', 'children': [], 'value': '" a,v from args "'}, {'id': '205', 'type': 'if_statement', 'children': ['206', '210']}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '210', 'type': 'block', 'children': ['211', '223']}, {'id': '211', 'type': 'assert_statement', 'children': ['212', '220']}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '219'], 'value': '=='}, {'id': '213', 'type': 'binary_operator', 'children': ['214', '218'], 'value': '%'}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '218', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '219', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '220', 'type': 'binary_operator', 'children': ['221', '222'], 'value': '%'}, {'id': '221', 'type': 'string', 'children': [], 'value': '"imbalanced a,v in args: "'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '223', 'type': 'for_statement', 'children': ['224', '227', '231']}; {'id': '224', 'type': 'pattern_list', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'second'}, {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'pairwise'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '231', 'type': 'block', 'children': ['232', '247']}; {'id': '232', 'type': 'if_statement', 'children': ['233', '240']}, {'id': '233', 'type': 'not_operator', 'children': ['234']}; {'id': '234', 'type': 'call', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'first'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '240', 'type': 'block', 'children': ['241']}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '244', 'type': 'binary_operator', 'children': ['245', '246'], 'value': '+'}, {'id': '245', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'first'}, {'id': '247', 'type': 'if_statement', 'children': ['248', '255', '290', '323', '357']}; {'id': '248', 'type': 'not_operator', 'children': ['249']}, {'id': '249', 'type': 'call', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'endswith'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '255', 'type': 'block', 'children': ['256', '258', '289']}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'string', 'children': [], 'value': '" longhand used: blah/blah "'}; {'id': '258', 'type': 'if_statement', 'children': ['259', '264', '278']}, {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '261', 'type': 'argument_list', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'second'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '264', 'type': 'block', 'children': ['265']}, {'id': '265', 'type': 'for_statement', 'children': ['266', '267', '268']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'second'}; {'id': '268', 'type': 'block', 'children': ['269']}, {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'addeav'}; {'id': '274', 'type': 'argument_list', 'children': ['275', '276', '277']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'first'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '278', 'type': 'else_clause', 'children': ['279']}, {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'addeav'}, {'id': '285', 'type': 'argument_list', 'children': ['286', '287', '288']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'entity'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'second'}, {'id': '289', 'type': 'continue_statement', 'children': []}; {'id': '290', 'type': 'elif_clause', 'children': ['291', '296']}, {'id': '291', 'type': 'call', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '293', 'type': 'argument_list', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'second'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '296', 'type': 'block', 'children': ['297', '299']}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'string', 'children': [], 'value': '" shorthand used: blah/, dict "'}, {'id': '299', 'type': 'for_statement', 'children': ['300', '303', '308']}; {'id': '300', 'type': 'pattern_list', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '303', 'type': 'call', 'children': ['304', '307']}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'second'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '307', 'type': 'argument_list', 'children': []}; {'id': '308', 'type': 'block', 'children': ['309', '322']}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'call', 'children': ['311', '314']}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'addeav'}; {'id': '314', 'type': 'argument_list', 'children': ['315', '316', '321']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '316', 'type': 'binary_operator', 'children': ['317', '318'], 'value': '%'}, {'id': '317', 'type': 'string', 'children': [], 'value': '"%s%s"'}; {'id': '318', 'type': 'tuple', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '322', 'type': 'continue_statement', 'children': []}, {'id': '323', 'type': 'elif_clause', 'children': ['324', '331']}; {'id': '324', 'type': 'call', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '326', 'type': 'argument_list', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'second'}; {'id': '328', 'type': 'tuple', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '331', 'type': 'block', 'children': ['332', '334']}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}, {'id': '333', 'type': 'string', 'children': [], 'value': '" shorthand used: blah/, list|tuple "'}; {'id': '334', 'type': 'for_statement', 'children': ['335', '338', '342']}, {'id': '335', 'type': 'pattern_list', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '338', 'type': 'call', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'pairwise'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'second'}; {'id': '342', 'type': 'block', 'children': ['343', '356']}, {'id': '343', 'type': 'expression_statement', 'children': ['344']}; {'id': '344', 'type': 'call', 'children': ['345', '348']}, {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'addeav'}; {'id': '348', 'type': 'argument_list', 'children': ['349', '350', '355']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '350', 'type': 'binary_operator', 'children': ['351', '352'], 'value': '%'}, {'id': '351', 'type': 'string', 'children': [], 'value': '"%s%s"'}; {'id': '352', 'type': 'tuple', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '356', 'type': 'continue_statement', 'children': []}, {'id': '357', 'type': 'else_clause', 'children': ['358']}; {'id': '358', 'type': 'block', 'children': ['359']}, {'id': '359', 'type': 'raise_statement', 'children': ['360']}; {'id': '360', 'type': 'expression_list', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '362', 'type': 'binary_operator', 'children': ['363', '364'], 'value': '%'}, {'id': '363', 'type': 'string', 'children': [], 'value': '"invalid pair: %s : %s"'}; {'id': '364', 'type': 'tuple', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'second'}, {'id': '367', 'type': 'expression_statement', 'children': ['368']}; {'id': '368', 'type': 'string', 'children': [], 'value': '"pass back the entity so it can be resolved after tx()"'}, {'id': '369', 'type': 'return_statement', 'children': ['370']}
def add(self, *args, **kwargs): assert self.resp is None, "Transaction already committed" entity, av_pairs, args = None, [], list(args) if len(args): if isinstance(args[0], (int, long)): " first arg is an entity or tempid" entity = E(args[0], tx=self) elif isinstance(args[0], E): " dont resuse entity from another tx" if args[0]._tx is self: entity = args[0] else: if int(args[0]) > 0: " use the entity id on a new obj" entity = E(int(args[0]), tx=self) args[0] = None " drop the first arg" if entity is not None or args[0] in (None, False, 0): v = args.pop(0) " auto generate a temp id?" if entity is None: entity = E(self.ctmpid, tx=self) self.ctmpid -= 1 " a,v from kwargs" if len(args) == 0 and kwargs: for a,v in kwargs.iteritems(): self.addeav(entity, a, v) " a,v from args " if len(args): assert len(args) % 2 == 0, "imbalanced a,v in args: " % args for first, second in pairwise(args): if not first.startswith(':'): first = ':' + first if not first.endswith('/'): " longhand used: blah/blah " if isinstance(second, list): for v in second: self.addeav(entity, first, v) else: self.addeav(entity, first, second) continue elif isinstance(second, dict): " shorthand used: blah/, dict " for a,v in second.iteritems(): self.addeav(entity, "%s%s" % (first, a), v) continue elif isinstance(second, (list, tuple)): " shorthand used: blah/, list|tuple " for a,v in pairwise(second): self.addeav(entity, "%s%s" % (first, a), v) continue else: raise Exception, "invalid pair: %s : %s" % (first,second) "pass back the entity so it can be resolved after tx()" return entity
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parsimonious_acr'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'num_tips'}; {'id': '10', 'type': 'block', 'children': ['11', '18', '24', '28', '41', '50', '173', '259', '356', '371']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'initialise_parsimonious_states'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16', '17']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'character'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'uppass'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '27', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '31', 'type': 'dictionary', 'children': ['32', '35', '38']}; {'id': '32', 'type': 'pair', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'STATES'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '35', 'type': 'pair', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'NUM_NODES'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}; {'id': '38', 'type': 'pair', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'NUM_TIPS'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'num_tips'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'string', 'children': [], 'value': "'pastml'"}; {'id': '50', 'type': 'function_definition', 'children': ['51', '52', '55']}, {'id': '51', 'type': 'function_name', 'children': [], 'value': 'process_result'}; {'id': '52', 'type': 'parameters', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '55', 'type': 'block', 'children': ['56', '69', '77', '96', '102', '114', '154', '160', '166']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'out_feature'}, {'id': '59', 'type': 'conditional_expression', 'children': ['60', '65', '68'], 'value': 'if'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_personalized_feature_name'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': '!='}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'character'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '76', 'type': 'argument_list', 'children': []}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '89', '90']}, {'id': '79', 'type': 'pattern_list', 'children': ['80', '83', '86']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'NUM_SCENARIOS'}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'NUM_UNRESOLVED_NODES'}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'NUM_STATES_PER_NODE'}, {'id': '89', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'choose_parsimonious_states'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94', '95']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'out_feature'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'augmented_assignment', 'children': ['98', '101'], 'value': '/='}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'NUM_STATES_PER_NODE'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'PERC_UNRESOLVED'}, {'id': '107', 'type': 'binary_operator', 'children': ['108', '113'], 'value': '/'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '112'], 'value': '*'}, {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'NUM_UNRESOLVED_NODES'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '100'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'num_nodes'}; {'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': 'debug'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '126']}, {'id': '121', 'type': 'attribute', 'children': ['122', '125']}; {'id': '122', 'type': 'concatenated_string', 'children': ['123', '124']}, {'id': '123', 'type': 'string', 'children': [], 'value': "'{} node{} unresolved ({:.2f}%) for {} by {}, '"}; {'id': '124', 'type': 'string', 'children': [], 'value': "'i.e. {:.4f} state{} per node in average.'"}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '130', '138', '141', '142', '143', '146']}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'NUM_UNRESOLVED_NODES'}; {'id': '130', 'type': 'conditional_expression', 'children': ['131', '132', '137'], 'value': 'if'}, {'id': '131', 'type': 'string', 'children': [], 'value': "'s are'"}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '136'], 'value': '!='}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'NUM_UNRESOLVED_NODES'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '137', 'type': 'string', 'children': [], 'value': "' is'"}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'PERC_UNRESOLVED'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'NUM_STATES_PER_NODE'}; {'id': '146', 'type': 'conditional_expression', 'children': ['147', '148', '153'], 'value': 'if'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'s'"}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '152'], 'value': '>'}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'NUM_STATES_PER_NODE'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '153', 'type': 'string', 'children': [], 'value': "''"}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '159']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'CHARACTER'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'out_feature'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '165']}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'METHOD'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'method'}; {'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': 'results'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '173', 'type': 'if_statement', 'children': ['174', '179']}; {'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': 'in'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}; {'id': '176', 'type': 'set', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'ACCTRAN'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'MP'}, {'id': '179', 'type': 'block', 'children': ['180', '188', '201', '208', '218', '224', '232']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'get_personalized_feature_name'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'character'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'PARS_STATES'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '192']}, {'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': '=='}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'MP'}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'get_personalized_feature_name'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'ACCTRAN'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'acctran'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'character'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '213']}; {'id': '210', 'type': 'subscript', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'STEPS'}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'get_num_parsimonious_steps'}, {'id': '215', 'type': 'argument_list', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'process_result'}, {'id': '221', 'type': 'argument_list', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'ACCTRAN'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'bu_feature'}, {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'get_personalized_feature_name'}, {'id': '229', 'type': 'argument_list', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'character'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'BU_PARS_STATES'}; {'id': '232', 'type': 'for_statement', 'children': ['233', '234', '239']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '234', 'type': 'call', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'traverse'}; {'id': '238', 'type': 'argument_list', 'children': []}, {'id': '239', 'type': 'block', 'children': ['240', '252']}; {'id': '240', 'type': 'if_statement', 'children': ['241', '244']}, {'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': '=='}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'ACCTRAN'}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'del_feature'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'bu_feature'}; {'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': 'node'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'del_feature'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '259', 'type': 'if_statement', 'children': ['260', '263']}; {'id': '260', 'type': 'comparison_operator', 'children': ['261', '262'], 'value': '!='}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'ACCTRAN'}, {'id': '263', 'type': 'block', 'children': ['264', '271', '279', '294', '307', '341']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'downpass'}, {'id': '267', 'type': 'argument_list', 'children': ['268', '269', '270']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '274', 'type': 'call', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'get_personalized_feature_name'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'PARS_STATES'}, {'id': '279', 'type': 'if_statement', 'children': ['280', '283']}; {'id': '280', 'type': 'comparison_operator', 'children': ['281', '282'], 'value': '=='}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'DOWNPASS'}, {'id': '283', 'type': 'block', 'children': ['284']}; {'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': 'result'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'STEPS'}, {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'get_num_parsimonious_steps'}, {'id': '291', 'type': 'argument_list', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '294', 'type': 'if_statement', 'children': ['295', '300']}, {'id': '295', 'type': 'comparison_operator', 'children': ['296', '297'], 'value': 'in'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '297', 'type': 'set', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'DOWNPASS'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'MP'}; {'id': '300', 'type': 'block', 'children': ['301']}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'call', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'process_result'}; {'id': '304', 'type': 'argument_list', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'DOWNPASS'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '307', 'type': 'if_statement', 'children': ['308', '313']}; {'id': '308', 'type': 'comparison_operator', 'children': ['309', '310'], 'value': 'in'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}; {'id': '310', 'type': 'set', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'DELTRAN'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'MP'}, {'id': '313', 'type': 'block', 'children': ['314', '320', '335']}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'deltran'}, {'id': '317', 'type': 'argument_list', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '320', 'type': 'if_statement', 'children': ['321', '324']}, {'id': '321', 'type': 'comparison_operator', 'children': ['322', '323'], 'value': '=='}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'prediction_method'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'DELTRAN'}; {'id': '324', 'type': 'block', 'children': ['325']}, {'id': '325', 'type': 'expression_statement', 'children': ['326']}; {'id': '326', 'type': 'assignment', 'children': ['327', '330']}, {'id': '327', 'type': 'subscript', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'STEPS'}; {'id': '330', 'type': 'call', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'get_num_parsimonious_steps'}; {'id': '332', 'type': 'argument_list', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'call', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'process_result'}; {'id': '338', 'type': 'argument_list', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'DELTRAN'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '341', 'type': 'for_statement', 'children': ['342', '343', '348']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '343', 'type': 'call', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'traverse'}, {'id': '347', 'type': 'argument_list', 'children': []}; {'id': '348', 'type': 'block', 'children': ['349']}, {'id': '349', 'type': 'expression_statement', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '354']}, {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'del_feature'}; {'id': '354', 'type': 'argument_list', 'children': ['355']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'feature'}; {'id': '356', 'type': 'expression_statement', 'children': ['357']}, {'id': '357', 'type': 'call', 'children': ['358', '361']}; {'id': '358', 'type': 'attribute', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '361', 'type': 'argument_list', 'children': ['362']}; {'id': '362', 'type': 'call', 'children': ['363', '366']}, {'id': '363', 'type': 'attribute', 'children': ['364', '365']}; {'id': '364', 'type': 'string', 'children': [], 'value': '"Parsimonious reconstruction for {} requires {} state changes."'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '366', 'type': 'argument_list', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'character'}; {'id': '368', 'type': 'subscript', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'STEPS'}, {'id': '371', 'type': 'return_statement', 'children': ['372']}
def parsimonious_acr(tree, character, prediction_method, states, num_nodes, num_tips): initialise_parsimonious_states(tree, character, states) uppass(tree, character) results = [] result = {STATES: states, NUM_NODES: num_nodes, NUM_TIPS: num_tips} logger = logging.getLogger('pastml') def process_result(method, feature): out_feature = get_personalized_feature_name(character, method) if prediction_method != method else character res = result.copy() res[NUM_SCENARIOS], res[NUM_UNRESOLVED_NODES], res[NUM_STATES_PER_NODE] \ = choose_parsimonious_states(tree, feature, out_feature) res[NUM_STATES_PER_NODE] /= num_nodes res[PERC_UNRESOLVED] = res[NUM_UNRESOLVED_NODES] * 100 / num_nodes logger.debug('{} node{} unresolved ({:.2f}%) for {} by {}, ' 'i.e. {:.4f} state{} per node in average.' .format(res[NUM_UNRESOLVED_NODES], 's are' if res[NUM_UNRESOLVED_NODES] != 1 else ' is', res[PERC_UNRESOLVED], character, method, res[NUM_STATES_PER_NODE], 's' if res[NUM_STATES_PER_NODE] > 1 else '')) res[CHARACTER] = out_feature res[METHOD] = method results.append(res) if prediction_method in {ACCTRAN, MP}: feature = get_personalized_feature_name(character, PARS_STATES) if prediction_method == MP: feature = get_personalized_feature_name(feature, ACCTRAN) acctran(tree, character, feature) result[STEPS] = get_num_parsimonious_steps(tree, feature) process_result(ACCTRAN, feature) bu_feature = get_personalized_feature_name(character, BU_PARS_STATES) for node in tree.traverse(): if prediction_method == ACCTRAN: node.del_feature(bu_feature) node.del_feature(feature) if prediction_method != ACCTRAN: downpass(tree, character, states) feature = get_personalized_feature_name(character, PARS_STATES) if prediction_method == DOWNPASS: result[STEPS] = get_num_parsimonious_steps(tree, feature) if prediction_method in {DOWNPASS, MP}: process_result(DOWNPASS, feature) if prediction_method in {DELTRAN, MP}: deltran(tree, character) if prediction_method == DELTRAN: result[STEPS] = get_num_parsimonious_steps(tree, feature) process_result(DELTRAN, feature) for node in tree.traverse(): node.del_feature(feature) logger.debug("Parsimonious reconstruction for {} requires {} state changes." .format(character, result[STEPS])) return results
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_seit_data'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'directory'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'frequency_file'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'frequencies.dat'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'data_prefix'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'volt_'"}, {'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '13', 'type': 'block', 'children': ['14', '29', '47', '62', '66', '96', '105']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'frequencies'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'loadtxt'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '28'], 'value': '+'}, {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '+'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'directory'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'frequency_file'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'data_files'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '46'], 'value': '+'}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '45'], 'value': '+'}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'directory'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sep'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'data_prefix'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '47', 'type': 'if_statement', 'children': ['48', '56']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '52'], 'value': '!='}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'frequencies'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'data_files'}; {'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': 'Exception'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'number of frequencies does not match number of data files'"}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'data_list'}, {'id': '65', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '66', 'type': 'for_statement', 'children': ['67', '70', '75']}, {'id': '67', 'type': 'pattern_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'frequency'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'frequencies'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'data_files'}, {'id': '75', 'type': 'block', 'children': ['76', '83', '89']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'subdata'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'load_mod_file'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '88']}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'subdata'}, {'id': '87', 'type': 'string', 'children': [], 'value': "'frequency'"}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'frequency'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'data_list'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'concat'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'data_list'}, {'id': '105', 'type': 'return_statement', 'children': ['106']}; {'id': '106', 'type': 'expression_list', 'children': ['107', '108', '109']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '108', 'type': 'None', 'children': []}, {'id': '109', 'type': 'None', 'children': []}
def load_seit_data(directory, frequency_file='frequencies.dat', data_prefix='volt_', **kwargs): frequencies = np.loadtxt(directory + os.sep + frequency_file) data_files = sorted(glob(directory + os.sep + data_prefix + '*')) if frequencies.size != len(data_files): raise Exception( 'number of frequencies does not match number of data files') data_list = [] for frequency, filename in zip(frequencies, data_files): subdata = load_mod_file(filename) subdata['frequency'] = frequency data_list.append(subdata) df = pd.concat(data_list) return df, None, None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_date'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '6', 'type': 'block', 'children': ['7', '30', '67']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': 'is'}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'date_format'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '29']}; {'id': '16', 'type': 'attribute', 'children': ['17', '28']}, {'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': 'datetime'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'strptime'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'date_format'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'if_statement', 'children': ['31', '38']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'\\d{8}$'"}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'list_splat', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '50', 'type': 'tuple', 'children': ['51', '56', '62']}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '53', 'type': 'slice', 'children': ['54', '55']}; {'id': '54', 'type': 'colon', 'children': []}, {'id': '55', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '58', 'type': 'slice', 'children': ['59', '60', '61']}, {'id': '59', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '60', 'type': 'colon', 'children': []}, {'id': '61', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '64', 'type': 'slice', 'children': ['65', '66']}, {'id': '65', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '66', 'type': 'colon', 'children': []}, {'id': '67', 'type': 'try_statement', 'children': ['68', '134']}; {'id': '68', 'type': 'block', 'children': ['69', '79']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'date_delim'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '79', 'type': 'if_statement', 'children': ['80', '86']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '85'], 'value': '=='}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'if_statement', 'children': ['88', '96', '109']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '95'], 'value': '=='}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'return_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'list_splat', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '109', 'type': 'elif_clause', 'children': ['110', '118']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '117'], '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': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '117', 'type': 'integer', 'children': [], 'value': '4'}; {'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': 'datetime'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'list_splat', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '134', 'type': 'except_clause', 'children': ['135', '136', '137']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'raise_statement', 'children': ['139']}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'reader'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'DataError'}, {'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': '\'Bad date format: "{}"\''}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'date'}
def parse_date(self, date): if self.date_format is not None: return datetime.datetime.strptime(date, self.date_format).date() if re.match('\d{8}$', date): return datetime.date(*map(int, (date[:4], date[4:6], date[6:]))) try: parts = date_delim.split(date, 2) if len(parts) == 3: if len(parts[0]) == 4: return datetime.date(*map(int, parts)) elif len(parts[2]) == 4: return datetime.date(*map(int, reversed(parts))) except TypeError, ValueError: raise reader.DataError('Bad date format: "{}"'.format(date))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'commit'}, {'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': 'if_match'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'wait'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '37', '52', '60', '91', '102', '117', '121', '180']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '20']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_changes'}; {'id': '20', 'type': 'block', 'children': ['21', '36']}, {'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': 'LOG'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28', '33']}, {'id': '27', 'type': 'string', 'children': [], 'value': '"No changes available for %s: %s"'}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'resource_id'}; {'id': '36', 'type': 'return_statement', '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': 'LOG'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44', '49']}, {'id': '43', 'type': 'string', 'children': [], 'value': '"Apply all the changes on the current %s: %s"'}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'resource_id'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_get_client'}, {'id': '59', 'type': 'argument_list', 'children': []}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'endpoint'}, {'id': '63', 'type': 'call', 'children': ['64', '69']}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': '_endpoint'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '77', '84']}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'resource_id'}; {'id': '72', 'type': 'boolean_operator', 'children': ['73', '76'], 'value': 'or'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'resource_id'}; {'id': '76', 'type': 'string', 'children': [], 'value': '""'}, {'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'parent_id'}, {'id': '79', 'type': 'boolean_operator', 'children': ['80', '83'], 'value': 'or'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'parent_id'}, {'id': '83', 'type': 'string', 'children': [], 'value': '""'}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'grandparent_id'}; {'id': '86', 'type': 'boolean_operator', 'children': ['87', '90'], 'value': 'or'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'grandparent_id'}; {'id': '90', 'type': 'string', 'children': [], 'value': '""'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'request_body'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'dump'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'include_read_only'}, {'id': '101', 'type': 'False', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'update_resource'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '111', '114']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'endpoint'}, {'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'request_body'}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'if_match'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'if_match'}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'elapsed_time'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '121', 'type': 'while_statement', 'children': ['122', '123', '171']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'wait'}, {'id': '123', 'type': 'block', 'children': ['124', '130', '138', '146', '160']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'refresh'}, {'id': '129', 'type': 'argument_list', 'children': []}; {'id': '130', 'type': 'if_statement', 'children': ['131', '136']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'is_ready'}, {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'break_statement', 'children': []}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'augmented_assignment', 'children': ['140', '141'], 'value': '+='}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'elapsed_time'}, {'id': '141', 'type': 'attribute', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'CONFIG'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'HNV'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'retry_interval'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '152']}, {'id': '147', 'type': 'boolean_operator', 'children': ['148', '149'], 'value': 'and'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '>'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'elapsed_time'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'raise_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'exception'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'TimeOut'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'string', 'children': [], 'value': '"The request timed out."'}; {'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': 'time'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'sleep'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'attribute', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'CONFIG'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'HNV'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'retry_interval'}, {'id': '171', 'type': 'else_clause', 'children': ['172']}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': '_reset_model'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '180', 'type': 'return_statement', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}
def commit(self, if_match=None, wait=True, timeout=None): if not self._changes: LOG.debug("No changes available for %s: %s", self.__class__.__name__, self.resource_id) return LOG.debug("Apply all the changes on the current %s: %s", self.__class__.__name__, self.resource_id) client = self._get_client() endpoint = self._endpoint.format( resource_id=self.resource_id or "", parent_id=self.parent_id or "", grandparent_id=self.grandparent_id or "") request_body = self.dump(include_read_only=False) response = client.update_resource(endpoint, data=request_body, if_match=if_match) elapsed_time = 0 while wait: self.refresh() if self.is_ready(): break elapsed_time += CONFIG.HNV.retry_interval if timeout and elapsed_time > timeout: raise exception.TimeOut("The request timed out.") time.sleep(CONFIG.HNV.retry_interval) else: self._reset_model(response) return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_histograms'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ertobj'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '30', '44', '56', '60', '70', '124', '414', '423']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '17', '22']}; {'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': 'ertobj'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ertobj'}; {'id': '22', 'type': 'else_clause', 'children': ['23']}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ertobj'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '38']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '37'], 'value': '=='}; {'id': '32', 'type': 'subscript', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'raise_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': "'No data present, cannot plot'"}; {'id': '44', 'type': 'if_statement', 'children': ['45', '50']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'str'}; {'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': 'keys'}; {'id': '54', 'type': 'list', 'children': ['55'], 'value': '[keys, ]'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'figures'}, {'id': '59', 'type': 'dictionary', 'children': []}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'merge_figs'}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'merge'"}, {'id': '69', 'type': 'True', 'children': []}; {'id': '70', 'type': 'if_statement', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'merge_figs'}; {'id': '72', 'type': 'block', 'children': ['73', '77', '84', '90', '98', '115']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'nr_x'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'nr_y'}; {'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': 'keys'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'size_x'}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '/'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '15'}, {'id': '89', 'type': 'float', 'children': [], 'value': '2.54'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'size_y'}, {'id': '93', 'type': 'binary_operator', 'children': ['94', '97'], 'value': '/'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '*'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'nr_y'}, {'id': '97', 'type': 'float', 'children': [], 'value': '2.54'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'pattern_list', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'axes_all'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'subplots'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '109', '110']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'nr_y'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'nr_x'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'figsize'}; {'id': '112', 'type': 'tuple', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'size_x'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'size_y'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'axes_all'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'atleast_2d'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'axes_all'}; {'id': '124', 'type': 'for_statement', 'children': ['125', '128', '132']}, {'id': '125', 'type': 'pattern_list', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'row_nr'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '132', 'type': 'block', 'children': ['133', '143', '151', '163', '174', '187', '199', '210', '246', '252', '265', '277', '284', '300', '315', '330', '398', '404']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'string', 'children': [], 'value': "'Generating histogram plot for key: {0}'"}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'subdata_raw'}; {'id': '146', 'type': 'attribute', 'children': ['147', '150']}, {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'subdata_raw'}; {'id': '156', 'type': 'unary_operator', 'children': ['157'], 'value': '~'}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'isnan'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'subdata_raw'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'isfinite'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'subdata_log10_with_nan'}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'log10'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'subscript', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': '>'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'subdata_log10'}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'subdata_log10_with_nan'}; {'id': '192', 'type': 'unary_operator', 'children': ['193'], 'value': '~'}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'isnan'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'subdata_log10_with_nan'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'subdata_log10'}; {'id': '202', 'type': 'subscript', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'subdata_log10'}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'isfinite'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'subdata_log10'}; {'id': '210', 'type': 'if_statement', 'children': ['211', '212', '223']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'merge_figs'}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '216', 'type': 'call', 'children': ['217', '222']}, {'id': '217', 'type': 'attribute', 'children': ['218', '221']}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'axes_all'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'row_nr'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'squeeze'}; {'id': '222', 'type': 'argument_list', 'children': []}, {'id': '223', 'type': 'else_clause', 'children': ['224']}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '230']}, {'id': '227', 'type': 'pattern_list', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'fig'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '230', 'type': 'call', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'plt'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'subplots'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236', '237']}, {'id': '235', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'figsize'}, {'id': '239', 'type': 'tuple', 'children': ['240', '243']}; {'id': '240', 'type': 'binary_operator', 'children': ['241', '242'], 'value': '/'}, {'id': '241', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '242', 'type': 'float', 'children': [], 'value': '2.54'}, {'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '/'}; {'id': '244', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '245', 'type': 'float', 'children': [], 'value': '2.54'}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '249', 'type': 'subscript', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '251', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'ax'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'hist'}, {'id': '257', 'type': 'argument_list', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'subdata'}, {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': '_get_nr_bins'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'size'}, {'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': 'ax'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'get_label'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'string', 'children': [], 'value': "'count'"}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'call', 'children': ['286', '291']}; {'id': '286', 'type': 'attribute', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'xaxis'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'set_major_locator'}, {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '298']}, {'id': '293', 'type': 'attribute', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'mpl'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'ticker'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'MaxNLocator'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}, {'id': '299', 'type': 'integer', 'children': [], 'value': '5'}; {'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': 'ax'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'tick_params'}, {'id': '305', 'type': 'argument_list', 'children': ['306', '309', '312']}; {'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '308', 'type': 'string', 'children': [], 'value': "'both'"}, {'id': '309', 'type': 'keyword_argument', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'which'}, {'id': '311', 'type': 'string', 'children': [], 'value': "'major'"}; {'id': '312', 'type': 'keyword_argument', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'labelsize'}; {'id': '314', 'type': 'integer', 'children': [], 'value': '6'}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'tick_params'}; {'id': '320', 'type': 'argument_list', 'children': ['321', '324', '327']}, {'id': '321', 'type': 'keyword_argument', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '323', 'type': 'string', 'children': [], 'value': "'both'"}; {'id': '324', 'type': 'keyword_argument', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'which'}; {'id': '326', 'type': 'string', 'children': [], 'value': "'minor'"}, {'id': '327', 'type': 'keyword_argument', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'labelsize'}, {'id': '329', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '330', 'type': 'if_statement', 'children': ['331', '336', '395']}, {'id': '331', 'type': 'comparison_operator', 'children': ['332', '335'], 'value': '>'}; {'id': '332', 'type': 'attribute', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'subdata_log10'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '335', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '336', 'type': 'block', 'children': ['337', '343', '356', '372', '379']}, {'id': '337', 'type': 'expression_statement', 'children': ['338']}; {'id': '338', 'type': 'assignment', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '340', 'type': 'subscript', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '342', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '343', 'type': 'expression_statement', 'children': ['344']}; {'id': '344', 'type': 'call', 'children': ['345', '348']}, {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '348', 'type': 'argument_list', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'subdata_log10'}; {'id': '350', 'type': 'call', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': '_get_nr_bins'}; {'id': '352', 'type': 'argument_list', 'children': ['353']}, {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'subdata'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '356', 'type': 'expression_statement', 'children': ['357']}, {'id': '357', 'type': 'call', 'children': ['358', '361']}; {'id': '358', 'type': 'attribute', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}, {'id': '361', 'type': 'argument_list', 'children': ['362']}; {'id': '362', 'type': 'binary_operator', 'children': ['363', '371'], 'value': '+'}, {'id': '363', 'type': 'binary_operator', 'children': ['364', '365'], 'value': '+'}; {'id': '364', 'type': 'string', 'children': [], 'value': "r'$log_{10}($'"}, {'id': '365', 'type': 'call', 'children': ['366', '369']}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'units'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'get_label'}, {'id': '369', 'type': 'argument_list', 'children': ['370']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '371', 'type': 'string', 'children': [], 'value': "')'"}; {'id': '372', 'type': 'expression_statement', 'children': ['373']}, {'id': '373', 'type': 'call', 'children': ['374', '377']}; {'id': '374', 'type': 'attribute', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}, {'id': '377', 'type': 'argument_list', 'children': ['378']}; {'id': '378', 'type': 'string', 'children': [], 'value': "'count'"}, {'id': '379', 'type': 'expression_statement', 'children': ['380']}; {'id': '380', 'type': 'call', 'children': ['381', '386']}, {'id': '381', 'type': 'attribute', 'children': ['382', '385']}; {'id': '382', 'type': 'attribute', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'xaxis'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'set_major_locator'}; {'id': '386', 'type': 'argument_list', 'children': ['387']}, {'id': '387', 'type': 'call', 'children': ['388', '393']}; {'id': '388', 'type': 'attribute', 'children': ['389', '392']}, {'id': '389', 'type': 'attribute', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'mpl'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'ticker'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'MaxNLocator'}, {'id': '393', 'type': 'argument_list', 'children': ['394']}; {'id': '394', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '395', 'type': 'else_clause', 'children': ['396']}; {'id': '396', 'type': 'block', 'children': ['397']}, {'id': '397', 'type': 'pass_statement', 'children': []}; {'id': '398', 'type': 'expression_statement', 'children': ['399']}, {'id': '399', 'type': 'call', 'children': ['400', '403']}; {'id': '400', 'type': 'attribute', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'tight_layout'}, {'id': '403', 'type': 'argument_list', 'children': []}; {'id': '404', 'type': 'if_statement', 'children': ['405', '407']}, {'id': '405', 'type': 'not_operator', 'children': ['406']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'merge_figs'}, {'id': '407', 'type': 'block', 'children': ['408']}; {'id': '408', 'type': 'expression_statement', 'children': ['409']}, {'id': '409', 'type': 'assignment', 'children': ['410', '413']}; {'id': '410', 'type': 'subscript', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'figures'}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '414', 'type': 'if_statement', 'children': ['415', '416']}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'merge_figs'}; {'id': '416', 'type': 'block', 'children': ['417']}, {'id': '417', 'type': 'expression_statement', 'children': ['418']}; {'id': '418', 'type': 'assignment', 'children': ['419', '422']}, {'id': '419', 'type': 'subscript', 'children': ['420', '421']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'figures'}, {'id': '421', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'fig'}, {'id': '423', 'type': 'return_statement', 'children': ['424']}
def plot_histograms(ertobj, keys, **kwargs): if isinstance(ertobj, pd.DataFrame): df = ertobj else: df = ertobj.data if df.shape[0] == 0: raise Exception('No data present, cannot plot') if isinstance(keys, str): keys = [keys, ] figures = {} merge_figs = kwargs.get('merge', True) if merge_figs: nr_x = 2 nr_y = len(keys) size_x = 15 / 2.54 size_y = 5 * nr_y / 2.54 fig, axes_all = plt.subplots(nr_y, nr_x, figsize=(size_x, size_y)) axes_all = np.atleast_2d(axes_all) for row_nr, key in enumerate(keys): print('Generating histogram plot for key: {0}'.format(key)) subdata_raw = df[key].values subdata = subdata_raw[~np.isnan(subdata_raw)] subdata = subdata[np.isfinite(subdata)] subdata_log10_with_nan = np.log10(subdata[subdata > 0]) subdata_log10 = subdata_log10_with_nan[~np.isnan( subdata_log10_with_nan) ] subdata_log10 = subdata_log10[np.isfinite(subdata_log10)] if merge_figs: axes = axes_all[row_nr].squeeze() else: fig, axes = plt.subplots(1, 2, figsize=(10 / 2.54, 5 / 2.54)) ax = axes[0] ax.hist( subdata, _get_nr_bins(subdata.size), ) ax.set_xlabel( units.get_label(key) ) ax.set_ylabel('count') ax.xaxis.set_major_locator(mpl.ticker.MaxNLocator(5)) ax.tick_params(axis='both', which='major', labelsize=6) ax.tick_params(axis='both', which='minor', labelsize=6) if subdata_log10.size > 0: ax = axes[1] ax.hist( subdata_log10, _get_nr_bins(subdata.size), ) ax.set_xlabel(r'$log_{10}($' + units.get_label(key) + ')') ax.set_ylabel('count') ax.xaxis.set_major_locator(mpl.ticker.MaxNLocator(5)) else: pass fig.tight_layout() if not merge_figs: figures[key] = fig if merge_figs: figures['all'] = fig return figures
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_histograms_extra_dims'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dataobj'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '30', '59', '63', '100', '104', '111', '121', '145', '155', '163', '171', '185', '193', '201', '224', '233', '237', '426', '445', '465', '471']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '17', '22']}; {'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': 'dataobj'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'df_raw'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dataobj'}; {'id': '22', 'type': 'else_clause', 'children': ['23']}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'df_raw'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dataobj'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '38', '53']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'subquery'"}, {'id': '37', 'type': 'False', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'df_raw'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'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']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'subquery'"}, {'id': '53', 'type': 'else_clause', 'children': ['54']}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'df_raw'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'split_timestamps'}; {'id': '62', 'type': 'True', 'children': []}, {'id': '63', 'type': 'if_statement', 'children': ['64', '65', '88']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'split_timestamps'}, {'id': '65', 'type': 'block', 'children': ['66', '75']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'group_timestamps'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'groupby'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'timestep'"}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'N_ts'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '87']}; {'id': '82', 'type': 'attribute', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'group_timestamps'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '87', 'type': 'argument_list', 'children': []}; {'id': '88', 'type': 'else_clause', 'children': ['89']}, {'id': '89', 'type': 'block', 'children': ['90', '96']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'group_timestamps'}, {'id': '93', 'type': 'tuple', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'all'"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'N_ts'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'N_c'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'plot_log10'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}, {'id': '119', 'type': 'string', 'children': [], 'value': "'log10plot'"}; {'id': '120', 'type': 'False', 'children': []}, {'id': '121', 'type': 'if_statement', 'children': ['122', '123', '134']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'plot_log10'}, {'id': '123', 'type': 'block', 'children': ['124', '130']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'transformers'}, {'id': '127', 'type': 'list', 'children': ['128', '129'], 'value': "['lin', 'log10']"}; {'id': '128', 'type': 'string', 'children': [], 'value': "'lin'"}, {'id': '129', 'type': 'string', 'children': [], 'value': "'log10'"}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'N_log10'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '134', 'type': 'else_clause', 'children': ['135']}, {'id': '135', 'type': 'block', 'children': ['136', '141']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'transformers'}, {'id': '139', 'type': 'list', 'children': ['140'], 'value': "['lin', ]"}; {'id': '140', 'type': 'string', 'children': [], 'value': "'lin'"}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'N_log10'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'Nx_max'}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'string', 'children': [], 'value': "'Nx'"}; {'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': 'N'}; {'id': '158', 'type': 'binary_operator', 'children': ['159', '162'], 'value': '*'}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '*'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'N_ts'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'N_c'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'N_log10'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'Nx'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'Nx_max'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'Ny'}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'ceil'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '/'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'Nx'}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'size_x'}; {'id': '188', 'type': 'binary_operator', 'children': ['189', '192'], 'value': '/'}, {'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '*'}; {'id': '190', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'Nx'}; {'id': '192', 'type': 'float', 'children': [], 'value': '2.54'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'size_y'}; {'id': '196', 'type': 'binary_operator', 'children': ['197', '200'], 'value': '/'}, {'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '*'}; {'id': '198', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'Ny'}; {'id': '200', 'type': 'float', 'children': [], 'value': '2.54'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '206']}, {'id': '203', 'type': 'pattern_list', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'fig'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '206', 'type': 'call', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'plt'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'subplots'}; {'id': '210', 'type': 'argument_list', 'children': ['211', '212', '213', '218', '221']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'Ny'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'Nx'}, {'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'figsize'}, {'id': '215', 'type': 'tuple', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'size_x'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'size_y'}; {'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'sharex'}; {'id': '220', 'type': 'True', 'children': []}, {'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'sharey'}, {'id': '223', 'type': 'True', 'children': []}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'atleast_2d'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '237', 'type': 'for_statement', 'children': ['238', '241', '242']}; {'id': '238', 'type': 'pattern_list', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ts_name'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'tgroup'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'group_timestamps'}; {'id': '242', 'type': 'block', 'children': ['243']}, {'id': '243', 'type': 'for_statement', 'children': ['244', '245', '246']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '246', 'type': 'block', 'children': ['247']}, {'id': '247', 'type': 'for_statement', 'children': ['248', '249', '250']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'transformer'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'transformers'}; {'id': '250', 'type': 'block', 'children': ['251', '259', '271', '282', '327', '335', '348', '360', '367', '383', '398', '413', '422']}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'subdata_raw'}; {'id': '254', 'type': 'attribute', 'children': ['255', '258']}, {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'tgroup'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'subdata_raw'}; {'id': '264', 'type': 'unary_operator', 'children': ['265'], 'value': '~'}, {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'isnan'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'subdata_raw'}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '274', 'type': 'subscript', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '276', 'type': 'call', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'isfinite'}; {'id': '280', 'type': 'argument_list', 'children': ['281']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '282', 'type': 'if_statement', 'children': ['283', '286']}, {'id': '283', 'type': 'comparison_operator', 'children': ['284', '285'], 'value': '=='}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'transformer'}, {'id': '285', 'type': 'string', 'children': [], 'value': "'log10'"}; {'id': '286', 'type': 'block', 'children': ['287', '300', '312', '323']}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'assignment', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'subdata_log10_with_nan'}; {'id': '290', 'type': 'call', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'log10'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'subscript', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'subdata'}, {'id': '297', 'type': 'comparison_operator', 'children': ['298', '299'], 'value': '>'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'subdata'}, {'id': '299', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'subdata_log10'}, {'id': '303', 'type': 'subscript', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'subdata_log10_with_nan'}, {'id': '305', 'type': 'unary_operator', 'children': ['306'], 'value': '~'}; {'id': '306', 'type': 'call', 'children': ['307', '310']}, {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'isnan'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'subdata_log10_with_nan'}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}, {'id': '313', 'type': 'assignment', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'subdata_log10'}, {'id': '315', 'type': 'subscript', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'subdata_log10'}, {'id': '317', 'type': 'call', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'isfinite'}, {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'subdata_log10'}, {'id': '323', 'type': 'expression_statement', 'children': ['324']}; {'id': '324', 'type': 'assignment', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'subdata_log10'}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'assignment', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '330', 'type': 'subscript', 'children': ['331', '334']}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'flat'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'call', 'children': ['337', '340']}, {'id': '337', 'type': 'attribute', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '340', 'type': 'argument_list', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'subdata'}; {'id': '342', 'type': 'call', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': '_get_nr_bins'}; {'id': '344', 'type': 'argument_list', 'children': ['345']}, {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'subdata'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '348', 'type': 'expression_statement', 'children': ['349']}, {'id': '349', 'type': 'call', 'children': ['350', '353']}; {'id': '350', 'type': 'attribute', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}, {'id': '353', 'type': 'argument_list', 'children': ['354']}; {'id': '354', 'type': 'call', 'children': ['355', '358']}, {'id': '355', 'type': 'attribute', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'units'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'get_label'}; {'id': '358', 'type': 'argument_list', 'children': ['359']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '360', 'type': 'expression_statement', 'children': ['361']}, {'id': '361', 'type': 'call', 'children': ['362', '365']}; {'id': '362', 'type': 'attribute', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}, {'id': '365', 'type': 'argument_list', 'children': ['366']}; {'id': '366', 'type': 'string', 'children': [], 'value': "'count'"}, {'id': '367', 'type': 'expression_statement', 'children': ['368']}; {'id': '368', 'type': 'call', 'children': ['369', '374']}, {'id': '369', 'type': 'attribute', 'children': ['370', '373']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'xaxis'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'set_major_locator'}; {'id': '374', 'type': 'argument_list', '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': 'mpl'}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'ticker'}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'MaxNLocator'}, {'id': '381', 'type': 'argument_list', 'children': ['382']}; {'id': '382', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '383', 'type': 'expression_statement', 'children': ['384']}; {'id': '384', 'type': 'call', 'children': ['385', '388']}, {'id': '385', 'type': 'attribute', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'tick_params'}; {'id': '388', 'type': 'argument_list', 'children': ['389', '392', '395']}, {'id': '389', 'type': 'keyword_argument', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '391', 'type': 'string', 'children': [], 'value': "'both'"}; {'id': '392', 'type': 'keyword_argument', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'which'}; {'id': '394', 'type': 'string', 'children': [], 'value': "'major'"}, {'id': '395', 'type': 'keyword_argument', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'labelsize'}, {'id': '397', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '398', 'type': 'expression_statement', 'children': ['399']}, {'id': '399', 'type': 'call', 'children': ['400', '403']}; {'id': '400', 'type': 'attribute', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'tick_params'}, {'id': '403', 'type': 'argument_list', 'children': ['404', '407', '410']}; {'id': '404', 'type': 'keyword_argument', 'children': ['405', '406']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '406', 'type': 'string', 'children': [], 'value': "'both'"}, {'id': '407', 'type': 'keyword_argument', 'children': ['408', '409']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'which'}, {'id': '409', 'type': 'string', 'children': [], 'value': "'minor'"}; {'id': '410', 'type': 'keyword_argument', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'labelsize'}; {'id': '412', 'type': 'integer', 'children': [], 'value': '6'}, {'id': '413', 'type': 'expression_statement', 'children': ['414']}; {'id': '414', 'type': 'call', 'children': ['415', '418']}, {'id': '415', 'type': 'attribute', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'set_title'}; {'id': '418', 'type': 'argument_list', 'children': ['419']}, {'id': '419', 'type': 'binary_operator', 'children': ['420', '421'], 'value': '%'}; {'id': '420', 'type': 'string', 'children': [], 'value': '"timestep: %d"'}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'ts_name'}; {'id': '422', 'type': 'expression_statement', 'children': ['423']}, {'id': '423', 'type': 'augmented_assignment', 'children': ['424', '425'], 'value': '+='}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '425', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '426', 'type': 'for_statement', 'children': ['427', '428', '437']}, {'id': '427', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '428', 'type': 'attribute', 'children': ['429', '436']}, {'id': '429', 'type': 'subscript', 'children': ['430', '431', '433']}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'axes'}, {'id': '431', 'type': 'slice', 'children': ['432']}; {'id': '432', 'type': 'colon', 'children': []}, {'id': '433', 'type': 'slice', 'children': ['434', '435']}; {'id': '434', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '435', 'type': 'colon', 'children': []}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'flat'}, {'id': '437', 'type': 'block', 'children': ['438']}; {'id': '438', 'type': 'expression_statement', 'children': ['439']}, {'id': '439', 'type': 'call', 'children': ['440', '443']}; {'id': '440', 'type': 'attribute', 'children': ['441', '442']}, {'id': '441', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}, {'id': '443', 'type': 'argument_list', 'children': ['444']}; {'id': '444', 'type': 'string', 'children': [], 'value': "''"}, {'id': '445', 'type': 'for_statement', 'children': ['446', '447', '457']}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '447', 'type': 'attribute', 'children': ['448', '456']}; {'id': '448', 'type': 'subscript', 'children': ['449', '450', '454']}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'axes'}; {'id': '450', 'type': 'slice', 'children': ['451', '452']}, {'id': '451', 'type': 'colon', 'children': []}; {'id': '452', 'type': 'unary_operator', 'children': ['453'], 'value': '-'}, {'id': '453', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '454', 'type': 'slice', 'children': ['455']}, {'id': '455', 'type': 'colon', 'children': []}; {'id': '456', 'type': 'identifier', 'children': [], 'value': 'flat'}, {'id': '457', 'type': 'block', 'children': ['458']}; {'id': '458', 'type': 'expression_statement', 'children': ['459']}, {'id': '459', 'type': 'call', 'children': ['460', '463']}; {'id': '460', 'type': 'attribute', 'children': ['461', '462']}, {'id': '461', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '462', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}, {'id': '463', 'type': 'argument_list', 'children': ['464']}; {'id': '464', 'type': 'string', 'children': [], 'value': "''"}, {'id': '465', 'type': 'expression_statement', 'children': ['466']}; {'id': '466', 'type': 'call', 'children': ['467', '470']}, {'id': '467', 'type': 'attribute', 'children': ['468', '469']}; {'id': '468', 'type': 'identifier', 'children': [], 'value': 'fig'}, {'id': '469', 'type': 'identifier', 'children': [], 'value': 'tight_layout'}; {'id': '470', 'type': 'argument_list', 'children': []}, {'id': '471', 'type': 'return_statement', 'children': ['472']}
def plot_histograms_extra_dims(dataobj, keys, **kwargs): if isinstance(dataobj, pd.DataFrame): df_raw = dataobj else: df_raw = dataobj.data if kwargs.get('subquery', False): df = df_raw.query(kwargs.get('subquery')) else: df = df_raw split_timestamps = True if split_timestamps: group_timestamps = df.groupby('timestep') N_ts = len(group_timestamps.groups.keys()) else: group_timestamps = ('all', df) N_ts = 1 columns = keys N_c = len(columns) plot_log10 = kwargs.get('log10plot', False) if plot_log10: transformers = ['lin', 'log10'] N_log10 = 2 else: transformers = ['lin', ] N_log10 = 1 Nx_max = kwargs.get('Nx', 4) N = N_ts * N_c * N_log10 Nx = min(Nx_max, N) Ny = int(np.ceil(N / Nx)) size_x = 5 * Nx / 2.54 size_y = 5 * Ny / 2.54 fig, axes = plt.subplots(Ny, Nx, figsize=(size_x, size_y), sharex=True, sharey=True) axes = np.atleast_2d(axes) index = 0 for ts_name, tgroup in group_timestamps: for column in columns: for transformer in transformers: subdata_raw = tgroup[column].values subdata = subdata_raw[~np.isnan(subdata_raw)] subdata = subdata[np.isfinite(subdata)] if transformer == 'log10': subdata_log10_with_nan = np.log10(subdata[subdata > 0]) subdata_log10 = subdata_log10_with_nan[~np.isnan( subdata_log10_with_nan) ] subdata_log10 = subdata_log10[np.isfinite(subdata_log10)] subdata = subdata_log10 ax = axes.flat[index] ax.hist( subdata, _get_nr_bins(subdata.size), ) ax.set_xlabel( units.get_label(column) ) ax.set_ylabel('count') ax.xaxis.set_major_locator(mpl.ticker.MaxNLocator(3)) ax.tick_params(axis='both', which='major', labelsize=6) ax.tick_params(axis='both', which='minor', labelsize=6) ax.set_title("timestep: %d" % ts_name) index += 1 for ax in axes[:, 1:].flat: ax.set_ylabel('') for ax in axes[:-1, :].flat: ax.set_xlabel('') fig.tight_layout() return fig
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'request'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'token_refresh_attempts'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '22', 'type': 'dictionary_splat_pattern', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '24', 'type': 'block', 'children': ['25', '54', '60', '69', '79', '88', '97', '122', '132', '146', '175']}, {'id': '25', 'type': 'if_statement', 'children': ['26', '32']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'list', 'children': ['30', '31'], 'value': '[data, json]'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '32', 'type': 'block', 'children': ['33', '40', '47']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '36', 'type': 'parenthesized_expression', 'children': ['37'], 'value': '()'}, {'id': '37', 'type': 'concatenated_string', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '\'"data" and "json" request parameters can not be used \''}, {'id': '39', 'type': 'string', 'children': [], 'value': "'at the same time'"}; {'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': 'logging'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '47', 'type': 'raise_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'exceptions'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'GCPHTTPError'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'req_headers'}, {'id': '57', 'type': 'boolean_operator', 'children': ['58', '59'], 'value': 'or'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '59', 'type': 'dictionary', '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': 'req_headers'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': '_utils'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_REQUEST_HEADERS'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'req_kwargs'}; {'id': '72', 'type': 'dictionary', 'children': ['73', '76']}, {'id': '73', 'type': 'pair', 'children': ['74', '75']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'params'"}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '76', 'type': 'pair', 'children': ['77', '78']}, {'id': '77', 'type': 'string', 'children': [], 'value': "'headers'"}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'req_headers'}, {'id': '79', 'type': 'if_statement', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'data'}, {'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': 'req_kwargs'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'data'"}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '96']}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'req_kwargs'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'json'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'token_refresh_attempts'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '108']}, {'id': '101', 'type': 'not_operator', 'children': ['102']}; {'id': '102', 'type': 'await', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'valid_token_set'}, {'id': '107', 'type': 'argument_list', 'children': []}; {'id': '108', 'type': 'block', 'children': ['109', '118']}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'await', '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': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': '_auth_client'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'refresh_token'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'augmented_assignment', 'children': ['120', '121'], 'value': '-='}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'token_refresh_attempts'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'req_headers'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'dictionary', 'children': ['129']}, {'id': '129', 'type': 'pair', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'Authorization'"}, {'id': '131', 'type': 'string', 'children': [], 'value': "f'Bearer {self._auth_client.token}'"}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'request_id'}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '141']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'request_id'"}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'uuid4'}, {'id': '145', 'type': 'argument_list', 'children': []}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'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': '_utils'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'REQ_LOG_FMT'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '162', '169', '172']}, {'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'request_id'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'request_id'}; {'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '168', 'type': 'argument_list', 'children': []}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'req_kwargs'}, {'id': '175', 'type': 'try_statement', 'children': ['176', '306', '338', '348']}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'with_statement', 'children': ['178', '194']}; {'id': '178', 'type': 'with_clause', 'children': ['179']}, {'id': '179', 'type': 'with_item', 'children': ['180']}; {'id': '180', 'type': 'as_pattern', 'children': ['181', '192']}, {'id': '181', 'type': 'call', 'children': ['182', '187']}; {'id': '182', 'type': 'attribute', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': '_session'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '187', 'type': 'argument_list', 'children': ['188', '189', '190']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '190', 'type': 'dictionary_splat', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'req_kwargs'}; {'id': '192', 'type': 'as_pattern_target', 'children': ['193']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '194', 'type': 'block', 'children': ['195', '224', '239', '293', '299']}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'log_kw'}; {'id': '198', 'type': 'dictionary', 'children': ['199', '202', '209', '214', '219']}, {'id': '199', 'type': 'pair', 'children': ['200', '201']}; {'id': '200', 'type': 'string', 'children': [], 'value': "'request_id'"}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'request_id'}; {'id': '202', 'type': 'pair', 'children': ['203', '204']}, {'id': '203', 'type': 'string', 'children': [], 'value': "'method'"}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '208', 'type': 'argument_list', 'children': []}, {'id': '209', 'type': 'pair', 'children': ['210', '211']}; {'id': '210', 'type': 'string', 'children': [], 'value': "'url'"}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '214', 'type': 'pair', 'children': ['215', '216']}, {'id': '215', 'type': 'string', 'children': [], 'value': "'status'"}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '219', 'type': 'pair', 'children': ['220', '221']}; {'id': '220', 'type': 'string', 'children': [], 'value': "'reason'"}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'reason'}; {'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': 'logging'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '236']}, {'id': '231', 'type': 'attribute', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': '_utils'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'RESP_LOG_FMT'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}, {'id': '237', 'type': 'dictionary_splat', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'log_kw'}, {'id': '239', 'type': 'if_statement', 'children': ['240', '245']}; {'id': '240', 'type': 'comparison_operator', 'children': ['241', '244'], 'value': 'in'}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'REFRESH_STATUS_CODES'}, {'id': '245', 'type': 'block', 'children': ['246', '255', '284']}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '251']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'concatenated_string', 'children': ['253', '254']}, {'id': '253', 'type': 'string', 'children': [], 'value': "f'[{request_id}] HTTP Status Code {resp.status}'"}; {'id': '254', 'type': 'string', 'children': [], 'value': "f' returned requesting {resp.url}: {resp.reason}'"}, {'id': '255', 'type': 'if_statement', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'token_refresh_attempts'}, {'id': '257', 'type': 'block', 'children': ['258', '267']}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'call', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'concatenated_string', 'children': ['265', '266']}, {'id': '265', 'type': 'string', 'children': [], 'value': "f'[{request_id}] Attempting request to {resp.url} '"}; {'id': '266', 'type': 'string', 'children': [], 'value': "'again.'"}, {'id': '267', 'type': 'return_statement', 'children': ['268']}; {'id': '268', 'type': 'await', 'children': ['269']}, {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '273', 'type': 'argument_list', 'children': ['274', '275', '276', '279', '282']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'token_refresh_attempts'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'token_refresh_attempts'}, {'id': '279', 'type': 'keyword_argument', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'request_id'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'request_id'}; {'id': '282', 'type': 'dictionary_splat', 'children': ['283']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'req_kwargs'}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'call', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'concatenated_string', 'children': ['291', '292']}, {'id': '291', 'type': 'string', 'children': [], 'value': "f'[{request_id}] Max attempts refreshing auth token '"}; {'id': '292', 'type': 'string', 'children': [], 'value': "f'exhausted while requesting {resp.url}'"}, {'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': 'resp'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'raise_for_status'}; {'id': '298', 'type': 'argument_list', 'children': []}, {'id': '299', 'type': 'return_statement', 'children': ['300']}; {'id': '300', 'type': 'await', 'children': ['301']}, {'id': '301', 'type': 'call', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '305', 'type': 'argument_list', 'children': []}; {'id': '306', 'type': 'except_clause', 'children': ['307', '313']}, {'id': '307', 'type': 'as_pattern', 'children': ['308', '311']}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'aiohttp'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'ClientResponseError'}, {'id': '311', 'type': 'as_pattern_target', 'children': ['312']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '313', 'type': 'block', 'children': ['314', '318', '328']}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}, {'id': '315', 'type': 'assignment', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '317', 'type': 'string', 'children': [], 'value': "f'[{request_id}] HTTP error response from {resp.url}: {e}'"}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '323', 'type': 'argument_list', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '325', 'type': 'keyword_argument', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'exc_info'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '328', 'type': 'raise_statement', 'children': ['329']}, {'id': '329', 'type': 'call', 'children': ['330', '333']}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'GCPHTTPResponseError'}, {'id': '333', 'type': 'argument_list', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'resp'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '338', 'type': 'except_clause', 'children': ['339', '345']}, {'id': '339', 'type': 'as_pattern', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'GCPHTTPResponseError'}, {'id': '343', 'type': 'as_pattern_target', 'children': ['344']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '345', 'type': 'block', 'children': ['346']}; {'id': '346', 'type': 'raise_statement', 'children': ['347']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '348', 'type': 'except_clause', 'children': ['349', '353']}, {'id': '349', 'type': 'as_pattern', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '351', 'type': 'as_pattern_target', 'children': ['352']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '353', 'type': 'block', 'children': ['354', '358', '368']}; {'id': '354', 'type': 'expression_statement', 'children': ['355']}, {'id': '355', 'type': 'assignment', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '357', 'type': 'string', 'children': [], 'value': "f'[{request_id}] Request call failed: {e}'"}; {'id': '358', 'type': 'expression_statement', 'children': ['359']}, {'id': '359', 'type': 'call', 'children': ['360', '363']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '363', 'type': 'argument_list', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '365', 'type': 'keyword_argument', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'exc_info'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '368', 'type': 'raise_statement', 'children': ['369']}, {'id': '369', 'type': 'call', 'children': ['370', '373']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'GCPHTTPError'}, {'id': '373', 'type': 'argument_list', 'children': ['374']}
async def request(self, method, url, params=None, headers=None, data=None, json=None, token_refresh_attempts=2, **kwargs): if all([data, json]): msg = ('"data" and "json" request parameters can not be used ' 'at the same time') logging.warn(msg) raise exceptions.GCPHTTPError(msg) req_headers = headers or {} req_headers.update(_utils.DEFAULT_REQUEST_HEADERS) req_kwargs = { 'params': params, 'headers': req_headers, } if data: req_kwargs['data'] = data if json: req_kwargs['json'] = json if token_refresh_attempts: if not await self.valid_token_set(): await self._auth_client.refresh_token() token_refresh_attempts -= 1 req_headers.update( {'Authorization': f'Bearer {self._auth_client.token}'} ) request_id = kwargs.get('request_id', uuid.uuid4()) logging.debug(_utils.REQ_LOG_FMT.format( request_id=request_id, method=method.upper(), url=url, kwargs=req_kwargs)) try: async with self._session.request(method, url, **req_kwargs) as resp: log_kw = { 'request_id': request_id, 'method': method.upper(), 'url': resp.url, 'status': resp.status, 'reason': resp.reason } logging.debug(_utils.RESP_LOG_FMT.format(**log_kw)) if resp.status in REFRESH_STATUS_CODES: logging.warning( f'[{request_id}] HTTP Status Code {resp.status}' f' returned requesting {resp.url}: {resp.reason}') if token_refresh_attempts: logging.info( f'[{request_id}] Attempting request to {resp.url} ' 'again.') return await self.request( method, url, token_refresh_attempts=token_refresh_attempts, request_id=request_id, **req_kwargs) logging.warning( f'[{request_id}] Max attempts refreshing auth token ' f'exhausted while requesting {resp.url}') resp.raise_for_status() return await resp.text() except aiohttp.ClientResponseError as e: msg = f'[{request_id}] HTTP error response from {resp.url}: {e}' logging.error(msg, exc_info=e) raise exceptions.GCPHTTPResponseError(msg, resp.status) except exceptions.GCPHTTPResponseError as e: raise e except Exception as e: msg = f'[{request_id}] Request call failed: {e}' logging.error(msg, exc_info=e) raise exceptions.GCPHTTPError(msg)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'unflatten'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'processed'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'merge_rules'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '179']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'unflattened'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '12', 'type': 'argument_list', 'children': []}, {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'processed'}; {'id': '16', 'type': 'block', 'children': ['17', '21']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'unflattened'}, {'id': '21', 'type': 'for_statement', 'children': ['22', '25', '30']}; {'id': '22', 'type': 'pattern_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'part'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'block', 'children': ['31', '105', '114', '124', '148', '169', '175']}, {'id': '31', 'type': 'if_statement', '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': 'part'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'IdValue'}, {'id': '37', 'type': 'block', 'children': ['38', '104']}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41', '62']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'current_node'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'if_statement', 'children': ['43', '56']}, {'id': '43', 'type': 'boolean_operator', 'children': ['44', '49'], 'value': 'and'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'IdDict'}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '53'], 'value': '=='}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'part'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'identifier'}; {'id': '56', 'type': 'block', 'children': ['57', '61']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '61', 'type': 'break_statement', 'children': []}; {'id': '62', 'type': 'else_clause', 'children': ['63']}, {'id': '63', 'type': 'block', 'children': ['64', '70', '78', '93', '100']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'new_node'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'IdDict'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'new_node'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'part'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'identifier'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '84']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '83'], 'value': 'is'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'original_value'}, {'id': '83', 'type': 'None', 'children': []}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '90']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'new_node'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'original_value'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'current_node'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'new_node'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'current_node'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'new_node'}; {'id': '104', 'type': 'continue_statement', 'children': []}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'current_node'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'is'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '117', 'type': 'None', 'children': []}; {'id': '118', 'type': 'block', 'children': ['119', '123']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '123', 'type': 'continue_statement', 'children': []}; {'id': '124', 'type': 'if_statement', 'children': ['125', '131']}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '130'], 'value': '=='}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '131', 'type': 'block', 'children': ['132', '147']}; {'id': '132', 'type': 'if_statement', 'children': ['133', '138']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '137'], 'value': 'is'}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'processed'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '137', 'type': 'None', 'children': []}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '144']}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'current_node'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'processed'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '147', 'type': 'continue_statement', 'children': []}; {'id': '148', 'type': 'if_statement', 'children': ['149', '156', '161']}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '151', 'type': 'argument_list', 'children': ['152', '155']}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'IdValue'}; {'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': 'new_node'}; {'id': '160', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '161', 'type': 'else_clause', 'children': ['162']}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'new_node'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '168', 'type': 'argument_list', 'children': []}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '174']}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'current_node'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'new_node'}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'new_node'}, {'id': '179', 'type': 'return_statement', 'children': ['180']}
def unflatten(processed, merge_rules): unflattened = OrderedDict() for key in processed: current_node = unflattened for end, part in enumerate(key, 1): if isinstance(part, IdValue): for node in current_node: if isinstance(node, IdDict) and node.identifier == part.identifier: current_node = node break else: new_node = IdDict() new_node.identifier = part.identifier if part.original_value is not None: new_node['id'] = part.original_value current_node.append(new_node) current_node = new_node continue node = current_node.get(part) if node is not None: current_node = node continue if len(key) == end: if processed[key] is not None: current_node[part] = processed[key] continue if isinstance(key[end], IdValue): new_node = [] else: new_node = OrderedDict() current_node[part] = new_node current_node = new_node return unflattened
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'translate'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '105']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'translations'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '15']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'LANGUAGES'}, {'id': '15', 'type': 'block', 'children': ['16', '28', '57']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '26']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '21'], 'value': '=='}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_get_default_language'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'continue_statement', 'children': []}; {'id': '28', 'type': 'if_statement', 'children': ['29', '34']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': 'is'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'translatable_slug'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'if_statement', 'children': ['36', '43']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': 'not'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'translatable_slug'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'translatable_fields'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'translatable_fields'}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '53'], 'value': '+'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'translatable_fields'}, {'id': '53', 'type': 'tuple', 'children': ['54']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'translatable_slug'}, {'id': '57', 'type': 'for_statement', 'children': ['58', '59', '62']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'translatable_fields'}; {'id': '62', 'type': 'block', 'children': ['63', '98']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}, {'id': '65', 'type': 'pattern_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'trans'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'created'}; {'id': '68', 'type': 'call', 'children': ['69', '74']}, {'id': '69', 'type': 'attribute', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'Translation'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'get_or_create'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '80', '90', '93']}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'object_id'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'content_type'}; {'id': '82', 'type': 'call', 'children': ['83', '88']}, {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ContentType'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'get_for_model'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'lang'}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'lang'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'translations'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'trans'}, {'id': '105', 'type': 'return_statement', 'children': ['106']}
def translate(self): translations = [] for lang in settings.LANGUAGES: if lang[0] == self._get_default_language(): continue if self.translatable_slug is not None: if self.translatable_slug not in self.translatable_fields: self.translatable_fields = self.translatable_fields + (self.translatable_slug,) for field in self.translatable_fields: trans, created = Translation.objects.get_or_create( object_id=self.id, content_type=ContentType.objects.get_for_model(self), field=field, lang=lang[0], ) translations.append(trans) return translations
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_translation'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '32', '45', '51', '57', '86', '129', '139', '147', '159']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'auto_slug_obj'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'if_statement', 'children': ['14', '21']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '=='}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_get_default_language'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'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': 'CanNotTranslate'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'concatenated_string', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'You are not supposed to translate the default language. '"}, {'id': '31', 'type': 'string', 'children': [], 'value': "'Use the model fields for translations in default language'"}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'trans_obj'}, {'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_translation_obj'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'lang'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'create'}; {'id': '44', 'type': 'True', 'children': []}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'trans_obj'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'translation'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'trans_obj'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '56', 'type': 'argument_list', 'children': []}, {'id': '57', 'type': 'if_statement', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'INSTALLED_AUTOSLUG'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'translatable_slug'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'try_statement', 'children': ['66', '82']}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'auto_slug_obj'}; {'id': '70', 'type': 'attribute', 'children': ['71', '81']}, {'id': '71', 'type': 'call', 'children': ['72', '77']}; {'id': '72', 'type': 'attribute', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'get_field'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'translatable_slug'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'populate_from'}; {'id': '82', 'type': 'except_clause', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'pass_statement', 'children': []}; {'id': '86', 'type': 'if_statement', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'auto_slug_obj'}; {'id': '88', 'type': 'block', 'children': ['89', '104', '114', '123']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'tobj'}; {'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': 'get_translation_obj'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98', '101']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'translatable_slug'}, {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'create'}, {'id': '103', 'type': 'True', 'children': []}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'translation'}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'get_translation'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'lang'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'auto_slug_obj'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'tobj'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'translation'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'slugify'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'translation'}, {'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': 'tobj'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '128', 'type': 'argument_list', 'children': []}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': '_get_translation_cache_key'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'cache'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'text'}, {'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': 'cache'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_get_translations_cache_key'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'lang'}, {'id': '159', 'type': 'return_statement', 'children': ['160']}
def set_translation(self, lang, field, text): auto_slug_obj = None if lang == self._get_default_language(): raise CanNotTranslate( _('You are not supposed to translate the default language. ' 'Use the model fields for translations in default language') ) trans_obj = self.get_translation_obj(lang, field, create=True) trans_obj.translation = text trans_obj.save() if INSTALLED_AUTOSLUG: if self.translatable_slug: try: auto_slug_obj = self._meta.get_field(self.translatable_slug).populate_from except AttributeError: pass if auto_slug_obj: tobj = self.get_translation_obj(lang, self.translatable_slug, create=True) translation = self.get_translation(lang, auto_slug_obj) tobj.translation = slugify(translation) tobj.save() key = self._get_translation_cache_key(lang, field) cache.set(key, text) cache.delete(self._get_translations_cache_key(lang)) return trans_obj
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'jsonify'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '7', 'type': 'unary_operator', 'children': ['8'], 'value': '-'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'parse_enums'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'PARSE_KEEP'}; {'id': '12', 'type': 'block', 'children': ['13', '20', '24', '183']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '=='}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'max_depth'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'augmented_assignment', 'children': ['22', '23'], 'value': '-='}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '30', '122', '144', '166']}, {'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': 'o'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '30', 'type': 'block', 'children': ['31', '42', '103']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'keyattrs'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '40', '41']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'_altnames'"}, {'id': '41', 'type': 'dictionary', 'children': []}; {'id': '42', 'type': 'function_definition', 'children': ['43', '44', '47']}, {'id': '43', 'type': 'function_name', 'children': [], 'value': '_getter'}; {'id': '44', 'type': 'parameters', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '47', 'type': 'block', 'children': ['48', '58', '67', '77', '90']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'keyattrs'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'other'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65', '66']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '67', 'type': 'if_statement', 'children': ['68', '72']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '77', 'type': 'if_statement', 'children': ['78', '83']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'Enum'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '90', 'type': 'return_statement', 'children': ['91']}, {'id': '91', 'type': 'expression_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'jsonify'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97', '100']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'other'}, {'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'max_depth'}; {'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'parse_enums'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'parse_enums'}, {'id': '103', 'type': 'return_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '106', 'type': 'generator_expression', 'children': ['107', '112']}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_getter'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '112', 'type': 'for_in_clause', 'children': ['113', '116']}, {'id': '113', 'type': 'pattern_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '122', 'type': 'elif_clause', 'children': ['123', '128']}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'return_statement', 'children': ['130']}; {'id': '130', 'type': 'list_comprehension', 'children': ['131', '141']}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'jsonify'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '135', '138']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'max_depth'}; {'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'parse_enums'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'parse_enums'}, {'id': '141', 'type': 'for_in_clause', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '144', 'type': 'elif_clause', 'children': ['145', '150']}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'generator_expression', 'children': ['153', '163']}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'jsonify'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '157', '160']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'max_depth'}; {'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'parse_enums'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'parse_enums'}, {'id': '163', 'type': 'for_in_clause', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '166', 'type': 'elif_clause', 'children': ['167', '172']}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'o'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'Enum'}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': '_parse_enum'}; {'id': '178', 'type': 'argument_list', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'parse_enums'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'parse_enums'}, {'id': '183', 'type': 'return_statement', 'children': ['184']}
def jsonify(o, max_depth=-1, parse_enums=PARSE_KEEP): if max_depth == 0: return o max_depth -= 1 if isinstance(o, dict): keyattrs = getattr(o.__class__, '_altnames', {}) def _getter(key, value): key = keyattrs.get(key, key) other = getattr(o, key, value) if callable(other): other = value if isinstance(key, Enum): key = key.name return key, jsonify(other, max_depth=max_depth, parse_enums=parse_enums) return dict(_getter(key, value) for key, value in six.iteritems(o)) elif isinstance(o, list): return [jsonify(x, max_depth=max_depth, parse_enums=parse_enums) for x in o] elif isinstance(o, tuple): return (jsonify(x, max_depth=max_depth, parse_enums=parse_enums) for x in o) elif isinstance(o, Enum): o = _parse_enum(o, parse_enums=parse_enums) return o
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'b58encode'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'charset'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_CHARSET'}; {'id': '8', 'type': 'block', 'children': ['9', '63', '85', '101', '108', '121', '128', '137', '144', '152', '174', '184', '196']}, {'id': '9', 'type': 'function_definition', 'children': ['10', '11', '22']}; {'id': '10', 'type': 'function_name', 'children': [], 'value': '_b58encode_int'}, {'id': '11', 'type': 'parameters', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'int_'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'bytes'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'list', 'children': ['19'], 'value': '[charset[0]]'}, {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'charset'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '22', 'type': 'block', 'children': ['23', '31', '35', '61']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '28']}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '27'], 'value': 'and'}, {'id': '25', 'type': 'not_operator', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'int_'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '34', 'type': 'string', 'children': [], 'value': "b''"}, {'id': '35', 'type': 'while_statement', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'int_'}, {'id': '37', 'type': 'block', 'children': ['38', '48']}; {'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': 'int_'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'divmod'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'int_'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '60'], 'value': '+'}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '54', 'type': 'slice', 'children': ['55', '56', '57']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '56', 'type': 'colon', 'children': []}, {'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '+'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '61', 'type': 'return_statement', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '63', 'type': 'if_statement', 'children': ['64', '70']}; {'id': '64', 'type': 'not_operator', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'raise_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '79'], 'value': '%'}; {'id': '76', 'type': 'concatenated_string', 'children': ['77', '78']}, {'id': '77', 'type': 'string', 'children': [], 'value': '"a bytes-like object is required, not \'%s\', "'}; {'id': '78', 'type': 'string', 'children': [], 'value': '"use .encode(\'ascii\') to encode unicode strings"'}, {'id': '79', 'type': 'attribute', 'children': ['80', '84']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '85', 'type': 'if_statement', 'children': ['86', '91']}; {'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': 'charset'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'charset'}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'ascii'"}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '113']}, {'id': '109', 'type': 'not_operator', 'children': ['110']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '=='}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '58'}, {'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': 'ValueError'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '%'}, {'id': '119', 'type': 'string', 'children': [], 'value': "'charset base must be 58, not %s'"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'pad_len'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'lstrip'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'string', 'children': [], 'value': "b'\\0'"}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'augmented_assignment', 'children': ['139', '140'], 'value': '-='}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'pad_len'}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '149']}; {'id': '146', 'type': 'pattern_list', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'acc'}, {'id': '149', 'type': 'expression_list', 'children': ['150', '151']}; {'id': '150', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '152', 'type': 'for_statement', 'children': ['153', '154', '161']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'deque'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '161', 'type': 'block', 'children': ['162', '168']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'augmented_assignment', 'children': ['164', '165'], 'value': '+='}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'acc'}, {'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '*'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '<<'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': '_b58encode_int'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'acc'}, {'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '183', 'type': 'False', 'children': []}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '187', 'type': 'binary_operator', 'children': ['188', '195'], 'value': '*'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'list', 'children': ['192'], 'value': '[charset[0]]'}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '194', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'pad_len'}; {'id': '196', 'type': 'return_statement', 'children': ['197']}, {'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '+'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'result'}
def b58encode(val, charset=DEFAULT_CHARSET): def _b58encode_int(int_, default=bytes([charset[0]])): if not int_ and default: return default output = b'' while int_: int_, idx = divmod(int_, base) output = charset[idx:idx+1] + output return output if not isinstance(val, bytes): raise TypeError( "a bytes-like object is required, not '%s', " "use .encode('ascii') to encode unicode strings" % type(val).__name__) if isinstance(charset, str): charset = charset.encode('ascii') base = len(charset) if not base == 58: raise ValueError('charset base must be 58, not %s' % base) pad_len = len(val) val = val.lstrip(b'\0') pad_len -= len(val) p, acc = 1, 0 for char in deque(reversed(val)): acc += p * char p = p << 8 result = _b58encode_int(acc, default=False) prefix = bytes([charset[0]]) * pad_len return prefix + result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'm2m_callback'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sender'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'pk_set'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'using'}, {'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '25']}, {'id': '15', 'type': 'boolean_operator', 'children': ['16', '20'], 'value': 'and'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'validate_instance'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '20', 'type': 'subscript', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'AUTOMATED_LOGGING'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'to_database'"}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '29', 'type': 'list', 'children': ['30', '31'], 'value': '["post_add", \'post_remove\']'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"post_add"'}, {'id': '31', 'type': 'string', 'children': [], 'value': "'post_remove'"}; {'id': '32', 'type': 'block', 'children': ['33', '50', '127', '211', '217', '223', '351', '357']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'modification'}; {'id': '36', 'type': 'list_comprehension', 'children': ['37', '47']}, {'id': '37', 'type': 'call', 'children': ['38', '43']}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pk'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'pk_set'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '64', '71']}, {'id': '51', 'type': 'boolean_operator', 'children': ['52', '61'], 'value': 'and'}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'in'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'al_chl'"}; {'id': '54', 'type': 'call', 'children': ['55', '60']}, {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '60', 'type': 'argument_list', 'children': []}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'al_chl'}; {'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': 'changelog'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'al_chl'}, {'id': '71', 'type': 'else_clause', 'children': ['72']}; {'id': '72', 'type': 'block', 'children': ['73', '79', '87', '98', '113', '121']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'changelog'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ModelChangelog'}; {'id': '78', 'type': 'argument_list', 'children': []}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'changelog'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'information'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ModelObject'}; {'id': '86', 'type': 'argument_list', 'children': []}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '94']}, {'id': '89', 'type': 'attribute', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'changelog'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'information'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '105']}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'changelog'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'information'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'type'}, {'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': 'ContentType'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'get_for_model'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'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': 'changelog'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'information'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '120', 'type': 'argument_list', 'children': []}, {'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': 'changelog'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '126', 'type': 'argument_list', 'children': []}, {'id': '127', 'type': 'for_statement', 'children': ['128', '129', '130']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'modification'}; {'id': '130', 'type': 'block', 'children': ['131', '137', '146', '180', '186']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ModelObject'}; {'id': '136', 'type': 'argument_list', 'children': []}, {'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': 'obj'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '146', 'type': 'try_statement', 'children': ['147', '161']}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '153', 'type': 'call', 'children': ['154', '159']}; {'id': '154', 'type': 'attribute', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'ContentType'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'get_for_model'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '161', 'type': 'except_clause', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '163', 'type': 'block', 'children': ['164', '173']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'getLogger'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'string', 'children': [], 'value': "'Could not determin the type of the modification.'"}; {'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': 'obj'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'save'}, {'id': '185', 'type': 'argument_list', 'children': []}; {'id': '186', 'type': 'if_statement', 'children': ['187', '190', '200']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': '=='}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '189', 'type': 'string', 'children': [], 'value': "'post_add'"}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '198']}, {'id': '193', 'type': 'attribute', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'changelog'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'inserted'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '200', 'type': 'else_clause', 'children': ['201']}, {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '209']}; {'id': '204', 'type': 'attribute', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'changelog'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'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': 'changelog'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '216', 'type': 'argument_list', 'children': []}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'al_chl'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'changelog'}, {'id': '223', 'type': 'if_statement', 'children': ['224', '233', '240']}; {'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': 'in'}, {'id': '225', 'type': 'string', 'children': [], 'value': "'al_evt'"}; {'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': 'instance'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '232', 'type': 'argument_list', 'children': []}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'al_evt'}; {'id': '240', 'type': 'else_clause', 'children': ['241']}, {'id': '241', 'type': 'block', 'children': ['242', '248', '256', '267', '273', '286', '303', '311', '322', '337', '345']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'Model'}, {'id': '247', 'type': 'argument_list', 'children': []}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'assignment', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'get_current_user'}, {'id': '255', 'type': 'argument_list', 'children': []}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '261', 'type': 'conditional_expression', 'children': ['262', '263', '266'], 'value': 'if'}; {'id': '262', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '263', 'type': 'comparison_operator', 'children': ['264', '265'], 'value': '=='}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '265', 'type': 'string', 'children': [], 'value': "'post_add'"}; {'id': '266', 'type': 'integer', 'children': [], 'value': '2'}, {'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': 'target'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '272', 'type': 'argument_list', 'children': []}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'ct'}; {'id': '276', 'type': 'attribute', 'children': ['277', '285']}, {'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': 'ContentType'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'get_for_model'}, {'id': '283', 'type': 'argument_list', 'children': ['284']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'app_label'}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'assignment', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'application'}, {'id': '291', 'type': 'subscript', 'children': ['292', '302']}; {'id': '292', 'type': 'call', 'children': ['293', '298']}, {'id': '293', 'type': 'attribute', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'Application'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'get_or_create'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}, {'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'ct'}; {'id': '302', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'information'}; {'id': '308', 'type': 'call', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'ModelObject'}; {'id': '310', 'type': 'argument_list', 'children': []}, {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '318']}, {'id': '313', 'type': 'attribute', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'information'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '318', 'type': 'call', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '322', 'type': 'expression_statement', 'children': ['323']}, {'id': '323', 'type': 'assignment', 'children': ['324', '329']}; {'id': '324', 'type': 'attribute', 'children': ['325', '328']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'information'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '329', 'type': 'call', 'children': ['330', '335']}; {'id': '330', 'type': 'attribute', 'children': ['331', '334']}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'ContentType'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'get_for_model'}, {'id': '335', 'type': 'argument_list', 'children': ['336']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '337', 'type': 'expression_statement', 'children': ['338']}; {'id': '338', 'type': 'call', 'children': ['339', '344']}, {'id': '339', 'type': 'attribute', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'information'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'save'}; {'id': '344', 'type': 'argument_list', 'children': []}, {'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': 'instance'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'al_evt'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '351', 'type': 'expression_statement', 'children': ['352']}; {'id': '352', 'type': 'assignment', 'children': ['353', '356']}, {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'modification'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'changelog'}, {'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': 'target'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'save'}
def m2m_callback(sender, instance, action, reverse, model, pk_set, using, **kwargs): if validate_instance(instance) and settings.AUTOMATED_LOGGING['to_database']: if action in ["post_add", 'post_remove']: modification = [model.objects.get(pk=x) for x in pk_set] if 'al_chl' in instance.__dict__.keys() and instance.al_chl: changelog = instance.al_chl else: changelog = ModelChangelog() changelog.information = ModelObject() changelog.information.value = repr(instance) changelog.information.type = ContentType.objects.get_for_model(instance) changelog.information.save() changelog.save() for f in modification: obj = ModelObject() obj.value = repr(f) try: obj.type = ContentType.objects.get_for_model(f) except Exception: logger = logging.getLogger(__name__) logger.debug('Could not determin the type of the modification.') obj.save() if action == 'post_add': changelog.inserted.add(obj) else: changelog.removed.add(obj) changelog.save() instance.al_chl = changelog if 'al_evt' in instance.__dict__.keys(): target = instance.al_evt else: target = Model() target.user = get_current_user() target.action = 2 if action == 'post_add' else 2 target.save() ct = ContentType.objects.get_for_model(instance).app_label target.application = Application.objects.get_or_create(name=ct)[0] target.information = ModelObject() target.information.value = repr(instance) target.information.type = ContentType.objects.get_for_model(instance) target.information.save() instance.al_evt = target target.modification = changelog target.save()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'normalize_allele_name'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'raw_allele'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'omit_dra1'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'infer_class2_pair'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '19', '28', '38', '46', '51', '77', '126', '135', '141']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'cache_key'}, {'id': '15', 'type': 'tuple', 'children': ['16', '17', '18']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'raw_allele'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'omit_dra1'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'infer_class2_pair'}, {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'in'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cache_key'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_normalized_allele_cache'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_normalized_allele_cache'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'cache_key'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'parsed_alleles'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'parse_classi_or_classii_allele_name'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'raw_allele'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'infer_pair'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'infer_class2_pair'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'species'}, {'id': '41', 'type': 'attribute', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'parsed_alleles'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'normalized_list'}, {'id': '49', 'type': 'list', 'children': ['50'], 'value': '[species]'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'species'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '60']}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '54'], 'value': 'and'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'omit_dra1'}; {'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': 'parsed_alleles'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '60', 'type': 'block', 'children': ['61', '67']}, {'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': 'alpha'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'parsed_alleles'}, {'id': '67', 'type': 'if_statement', 'children': ['68', '71']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '=='}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_DRA1_0101'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'parsed_alleles'}, {'id': '75', 'type': 'list', 'children': ['76'], 'value': '[beta]'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'beta'}, {'id': '77', 'type': 'for_statement', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'parsed_allele'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'parsed_alleles'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'if_statement', 'children': ['82', '90', '109']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '89'], 'value': '>'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'parsed_allele'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'allele_family'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'normalized_list'}, {'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:%s"'}, {'id': '99', 'type': 'tuple', 'children': ['100', '103', '106']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'parsed_allele'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'gene'}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'parsed_allele'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'allele_family'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'parsed_allele'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'allele_code'}, {'id': '109', 'type': 'else_clause', 'children': ['110']}; {'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': 'normalized_list'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '%'}; {'id': '118', 'type': 'string', 'children': [], 'value': '"%s%s"'}, {'id': '119', 'type': 'tuple', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'parsed_allele'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'gene'}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'parsed_allele'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'allele_code'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'normalized'}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'normalized_list'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '140']}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': '_normalized_allele_cache'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'cache_key'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'normalized'}, {'id': '141', 'type': 'return_statement', 'children': ['142']}
def normalize_allele_name(raw_allele, omit_dra1=False, infer_class2_pair=True): cache_key = (raw_allele, omit_dra1, infer_class2_pair) if cache_key in _normalized_allele_cache: return _normalized_allele_cache[cache_key] parsed_alleles = parse_classi_or_classii_allele_name( raw_allele, infer_pair=infer_class2_pair) species = parsed_alleles[0].species normalized_list = [species] if omit_dra1 and len(parsed_alleles) == 2: alpha, beta = parsed_alleles if alpha == _DRA1_0101: parsed_alleles = [beta] for parsed_allele in parsed_alleles: if len(parsed_allele.allele_family) > 0: normalized_list.append("%s*%s:%s" % ( parsed_allele.gene, parsed_allele.allele_family, parsed_allele.allele_code)) else: normalized_list.append("%s%s" % ( parsed_allele.gene, parsed_allele.allele_code)) normalized = "-".join(normalized_list) _normalized_allele_cache[cache_key] = normalized return normalized