sequence
stringlengths
1.25k
34.6k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_update_pot_file'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '7', 'type': 'block', 'children': ['8', '11', '14', '18', '27', '37', '45', '53', '64', '81', '91', '166', '183', '193', '200', '205', '211', '312']},{'id': '8', 'type': 'import_statement', 'children': ['9']},{'id': '9', 'type': 'dotted_name', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '11', 'type': 'import_statement', 'children': ['12']},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '14', 'type': 'import_statement', 'children': ['15']},{'id': '15', 'type': 'dotted_name', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'nop'},{'id': '21', 'type': 'lambda', 'children': ['22', '26']},{'id': '22', 'type': 'lambda_parameters', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'save_cwd'},{'id': '30', 'type': 'call', 'children': ['31', '36']},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'save_os_cwd'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'chdir_str'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'get_abspath'},{'id': '63', 'type': 'argument_list', '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': 'env'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'Execute'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'nop'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '+'},{'id': '79', 'type': 'string', 'children': [], 'value': '"Entering "'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'chdir_str'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'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': 'env'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '90', 'type': 'integer', 'children': [], 'value': '1'},{'id': '91', 'type': 'try_statement', 'children': ['92', '129']},{'id': '92', 'type': 'block', 'children': ['93', '101', '117']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': '_CmdRunner'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'$XGETTEXTCOM'"},{'id': '100', 'type': 'string', 'children': [], 'value': "'$XGETTEXTCOMSTR'"},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'action'},{'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': 'SCons'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'strfunction'},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'strfunction'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '122', 'type': 'argument_list', 'children': ['123', '127', '128']},{'id': '123', 'type': 'list', 'children': ['124'], 'value': '[target[0]]'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '126', 'type': 'integer', 'children': [], 'value': '0'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '129', 'type': 'except_clause', 'children': ['130']},{'id': '130', 'type': 'block', 'children': ['131', '148', '158', '165']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'Execute'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '143']},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'nop'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '+'},{'id': '146', 'type': 'string', 'children': [], 'value': '"Leaving "'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'chdir_str'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '155']},{'id': '150', 'type': 'attribute', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'save_cwd'},{'id': '157', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'os'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'save_os_cwd'},{'id': '165', 'type': 'raise_statement', 'children': []},{'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': 'env'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'Execute'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '178']},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'nop'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '+'},{'id': '181', 'type': 'string', 'children': [], 'value': '"Leaving "'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'chdir_str'},{'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': 'env'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '190', 'type': 'argument_list', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'save_cwd'},{'id': '192', 'type': 'integer', 'children': [], 'value': '0'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'save_os_cwd'},{'id': '200', 'type': 'if_statement', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'return_statement', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'new_content'},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '211', 'type': 'if_statement', 'children': ['212', '214', '223']},{'id': '212', 'type': 'not_operator', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'new_content'},{'id': '214', 'type': 'block', 'children': ['215', '219']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'needs_update'},{'id': '218', 'type': 'False', 'children': []},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'explain'},{'id': '222', 'type': 'string', 'children': [], 'value': '"no internationalized messages encountered"'},{'id': '223', 'type': 'else_clause', 'children': ['224']},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'if_statement', 'children': ['226', '233', '302']},{'id': '226', 'type': 'call', 'children': ['227', '232']},{'id': '227', 'type': 'attribute', 'children': ['228', '231']},{'id': '228', 'type': 'subscript', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '230', 'type': 'integer', 'children': [], 'value': '0'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '232', 'type': 'argument_list', 'children': []},{'id': '233', 'type': 'block', 'children': ['234', '244', '256', '267', '278']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'old_content'},{'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': 'target'},{'id': '241', 'type': 'integer', 'children': [], 'value': '0'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'get_text_contents'},{'id': '243', 'type': 'argument_list', 'children': []},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 're_cdate'},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '251', 'type': 'argument_list', 'children': ['252', '253']},{'id': '252', 'type': 'string', 'children': [], 'value': 'r\'^"POT-Creation-Date: .*"$[\\r\\n]?\''},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'M'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'old_content_nocdate'},{'id': '259', 'type': 'call', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '263', 'type': 'argument_list', 'children': ['264', '265', '266']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 're_cdate'},{'id': '265', 'type': 'string', 'children': [], 'value': '""'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'old_content'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'new_content_nocdate'},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '274', 'type': 'argument_list', 'children': ['275', '276', '277']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 're_cdate'},{'id': '276', 'type': 'string', 'children': [], 'value': '""'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'new_content'},{'id': '278', 'type': 'if_statement', 'children': ['279', '283', '292']},{'id': '279', 'type': '()', 'children': ['280']},{'id': '280', 'type': 'comparison_operator', 'children': ['281', '282'], 'value': '=='},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'old_content_nocdate'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'new_content_nocdate'},{'id': '283', 'type': 'block', 'children': ['284', '288']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'needs_update'},{'id': '287', 'type': 'False', 'children': []},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'explain'},{'id': '291', 'type': 'string', 'children': [], 'value': '"messages in file found to be up-to-date"'},{'id': '292', 'type': 'else_clause', 'children': ['293']},{'id': '293', 'type': 'block', 'children': ['294', '298']},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'needs_update'},{'id': '297', 'type': 'True', 'children': []},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'explain'},{'id': '301', 'type': 'string', 'children': [], 'value': '"messages in file were outdated"'},{'id': '302', 'type': 'else_clause', 'children': ['303']},{'id': '303', 'type': 'block', 'children': ['304', '308']},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'assignment', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'needs_update'},{'id': '307', 'type': 'True', 'children': []},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'assignment', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'explain'},{'id': '311', 'type': 'string', 'children': [], 'value': '"new file"'},{'id': '312', 'type': 'if_statement', 'children': ['313', '314', '378']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'needs_update'},{'id': '314', 'type': 'block', 'children': ['315', '335', '350', '363', '370', '376']},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'assignment', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '318', 'type': 'binary_operator', 'children': ['319', '334'], 'value': '+'},{'id': '319', 'type': 'binary_operator', 'children': ['320', '333'], 'value': '+'},{'id': '320', 'type': 'binary_operator', 'children': ['321', '332'], 'value': '+'},{'id': '321', 'type': 'binary_operator', 'children': ['322', '323'], 'value': '+'},{'id': '322', 'type': 'string', 'children': [], 'value': '"Writing "'},{'id': '323', 'type': 'call', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '325', 'type': 'argument_list', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'subscript', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '331', 'type': 'integer', 'children': [], 'value': '0'},{'id': '332', 'type': 'string', 'children': [], 'value': '" ("'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'explain'},{'id': '334', 'type': 'string', 'children': [], 'value': '")"'},{'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': 'env'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'Execute'},{'id': '340', 'type': 'argument_list', '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': 'SCons'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '347', 'type': 'argument_list', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'nop'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'assignment', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '353', 'type': 'call', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '355', 'type': 'argument_list', 'children': ['356', '362']},{'id': '356', 'type': 'call', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '358', 'type': 'argument_list', 'children': ['359']},{'id': '359', 'type': 'subscript', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '361', 'type': 'integer', 'children': [], 'value': '0'},{'id': '362', 'type': 'string', 'children': [], 'value': '"w"'},{'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': 'f'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '368', 'type': 'argument_list', 'children': ['369']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'new_content'},{'id': '370', 'type': 'expression_statement', 'children': ['371']},{'id': '371', 'type': 'call', 'children': ['372', '375']},{'id': '372', 'type': 'attribute', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '375', 'type': 'argument_list', 'children': []},{'id': '376', 'type': 'return_statement', 'children': ['377']},{'id': '377', 'type': 'integer', 'children': [], 'value': '0'},{'id': '378', 'type': 'else_clause', 'children': ['379']},{'id': '379', 'type': 'block', 'children': ['380', '400', '415']},{'id': '380', 'type': 'expression_statement', 'children': ['381']},{'id': '381', 'type': 'assignment', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '383', 'type': 'binary_operator', 'children': ['384', '399'], 'value': '+'},{'id': '384', 'type': 'binary_operator', 'children': ['385', '398'], 'value': '+'},{'id': '385', 'type': 'binary_operator', 'children': ['386', '397'], 'value': '+'},{'id': '386', 'type': 'binary_operator', 'children': ['387', '388'], 'value': '+'},{'id': '387', 'type': 'string', 'children': [], 'value': '"Not writing "'},{'id': '388', 'type': 'call', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '390', 'type': 'argument_list', 'children': ['391']},{'id': '391', 'type': 'call', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '393', 'type': 'argument_list', 'children': ['394']},{'id': '394', 'type': 'subscript', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '396', 'type': 'integer', 'children': [], 'value': '0'},{'id': '397', 'type': 'string', 'children': [], 'value': '" ("'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'explain'},{'id': '399', 'type': 'string', 'children': [], 'value': '")"'},{'id': '400', 'type': 'expression_statement', 'children': ['401']},{'id': '401', 'type': 'call', 'children': ['402', '405']},{'id': '402', 'type': 'attribute', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'Execute'},{'id': '405', 'type': 'argument_list', 'children': ['406']},{'id': '406', 'type': 'call', 'children': ['407', '412']},{'id': '407', 'type': 'attribute', 'children': ['408', '411']},{'id': '408', 'type': 'attribute', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '412', 'type': 'argument_list', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'nop'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '415', 'type': 'return_statement', 'children': ['416']},{'id': '416', 'type': 'integer', 'children': [], 'value': '0'}
def _update_pot_file(target, source, env): import re import os import SCons.Action nop = lambda target, source, env: 0 save_cwd = env.fs.getcwd() save_os_cwd = os.getcwd() chdir = target[0].dir chdir_str = repr(chdir.get_abspath()) env.Execute(SCons.Action.Action(nop, "Entering " + chdir_str)) env.fs.chdir(chdir, 1) try: cmd = _CmdRunner('$XGETTEXTCOM', '$XGETTEXTCOMSTR') action = SCons.Action.Action(cmd, strfunction=cmd.strfunction) status = action([target[0]], source, env) except: env.Execute(SCons.Action.Action(nop, "Leaving " + chdir_str)) env.fs.chdir(save_cwd, 0) os.chdir(save_os_cwd) raise env.Execute(SCons.Action.Action(nop, "Leaving " + chdir_str)) env.fs.chdir(save_cwd, 0) os.chdir(save_os_cwd) if status: return status new_content = cmd.out if not new_content: needs_update = False explain = "no internationalized messages encountered" else: if target[0].exists(): old_content = target[0].get_text_contents() re_cdate = re.compile(r'^"POT-Creation-Date: .*"$[\r\n]?', re.M) old_content_nocdate = re.sub(re_cdate, "", old_content) new_content_nocdate = re.sub(re_cdate, "", new_content) if (old_content_nocdate == new_content_nocdate): needs_update = False explain = "messages in file found to be up-to-date" else: needs_update = True explain = "messages in file were outdated" else: needs_update = True explain = "new file" if needs_update: msg = "Writing " + repr(str(target[0])) + " (" + explain + ")" env.Execute(SCons.Action.Action(nop, msg)) f = open(str(target[0]), "w") f.write(new_content) f.close() return 0 else: msg = "Not writing " + repr(str(target[0])) + " (" + explain + ")" env.Execute(SCons.Action.Action(nop, msg)) return 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'ERROR', 'children': ['2', '321']},{'id': '2', 'type': 'function_definition', 'children': ['3', '4', '14', '211']},{'id': '3', 'type': 'function_name', 'children': [], 'value': '_scan_xgettext_from_files'},{'id': '4', 'type': 'parameters', 'children': ['5', '6', '7', '8', '11']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'ERROR', 'children': ['15', '18', '22', '27', '34', '50', '72', '88', '99', '103', '167', '182', '183', '186', '187']},{'id': '15', 'type': 'import_statement', 'children': ['16']},{'id': '16', 'type': 'dotted_name', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '18', 'type': 'import_statement', 'children': ['19']},{'id': '19', 'type': 'dotted_name', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '22', 'type': 'import_statement', 'children': ['23']},{'id': '23', 'type': 'dotted_name', 'children': ['24', '25', '26']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'FS'},{'id': '27', 'type': 'if_statement', 'children': ['28', '31']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'if_statement', 'children': ['35', '44']},{'id': '35', 'type': 'not_operator', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'is_List'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '48', 'type': 'list', 'children': ['49'], 'value': '[files]'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '50', 'type': 'if_statement', 'children': ['51', '54']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'if_statement', 'children': ['56', '59', '66']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'},{'id': '57', 'type': 'string', 'children': [], 'value': "'XGETTEXTPATH'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'env'},{'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': 'path'},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '65', 'type': 'string', 'children': [], 'value': "'XGETTEXTPATH'"},{'id': '66', 'type': 'else_clause', 'children': ['67']},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '71', 'type': 'list', 'children': [], 'value': '[]'},{'id': '72', 'type': 'if_statement', 'children': ['73', '82']},{'id': '73', 'type': 'not_operator', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'is_List'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '86', 'type': 'list', 'children': ['87'], 'value': '[path]'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'path'},{'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': 'SCons'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '102', 'type': 'tuple', 'children': []},{'id': '103', 'type': 'for_statement', 'children': ['104', '105', '106']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '106', 'type': 'block', 'children': ['107', '160']},{'id': '107', 'type': 'if_statement', 'children': ['108', '120']},{'id': '108', 'type': 'not_operator', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '113', 'type': 'attribute', 'children': ['114', '119']},{'id': '114', 'type': 'attribute', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'FS'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'Base'},{'id': '120', 'type': 'block', 'children': ['121', '146']},{'id': '121', 'type': 'if_statement', 'children': ['122', '130']},{'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': 'SCons'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'is_String'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'p'},{'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': 'p'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140', '143']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'arg2nodes'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'Dir'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'augmented_assignment', 'children': ['162', '163'], 'value': '+='},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '167', 'type': 'if_statement', 'children': ['168', '170']},{'id': '168', 'type': 'not_operator', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '174', 'type': 'tuple', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '181']},{'id': '176', 'type': 'attribute', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'fs'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '181', 'type': 'argument_list', 'children': []},{'id': '182', 'type': 'identifier', 'children': [], 'value': 're_comment'},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '186', 'type': 'ERROR', 'children': []},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 're_emptyln'},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '207', '210'], 'value': 'in'},{'id': '190', 'type': 'call', 'children': ['191', '205']},{'id': '191', 'type': 'attribute', 'children': ['192', '201', '204']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': "r'^[ \\t\\r]*$\\r?\\n?'"},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'M'},{'id': '201', 'type': 'ERROR', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 're_trailws'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'string', 'children': [], 'value': "r'[ \\t\\r]+$'"},{'id': '207', 'type': 'ERROR', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'for'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'if_statement', 'children': ['213', '230']},{'id': '213', 'type': 'boolean_operator', 'children': ['214', '225'], 'value': 'and'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '218', 'type': 'attribute', 'children': ['219', '224']},{'id': '219', 'type': 'attribute', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'FS'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'Base'},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'rexists'},{'id': '229', 'type': 'argument_list', 'children': []},{'id': '230', 'type': 'block', 'children': ['231', '239', '249', '259', '269', '277']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'get_text_contents'},{'id': '238', 'type': 'argument_list', 'children': []},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 're_comment'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '246', 'type': 'argument_list', 'children': ['247', '248']},{'id': '247', 'type': 'string', 'children': [], 'value': '""'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 're_emptyln'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '256', 'type': 'argument_list', 'children': ['257', '258']},{'id': '257', 'type': 'string', 'children': [], 'value': '""'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 're_trailws'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '266', 'type': 'argument_list', 'children': ['267', '268']},{'id': '267', 'type': 'string', 'children': [], 'value': '""'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'depnames'},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '276', 'type': 'argument_list', 'children': []},{'id': '277', 'type': 'for_statement', 'children': ['278', '279', '280']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'depname'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'depnames'},{'id': '280', 'type': 'block', 'children': ['281', '295', '313']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'depfile'},{'id': '284', 'type': 'call', 'children': ['285', '292']},{'id': '285', 'type': 'attribute', 'children': ['286', '291']},{'id': '286', 'type': 'attribute', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'FS'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'find_file'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'depname'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '295', 'type': 'if_statement', 'children': ['296', '298']},{'id': '296', 'type': 'not_operator', 'children': ['297']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'depfile'},{'id': '298', 'type': 'block', 'children': ['299']},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'depfile'},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'arg2nodes'},{'id': '306', 'type': 'argument_list', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'depname'},{'id': '308', 'type': 'attribute', 'children': ['309', '312']},{'id': '309', 'type': 'subscript', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '311', 'type': 'integer', 'children': [], 'value': '0'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'Depends'},{'id': '318', 'type': 'argument_list', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'depfile'},{'id': '321', 'type': 'return_statement', 'children': ['322']},{'id': '322', 'type': 'integer', 'children': [], 'value': '0'}
def _scan_xgettext_from_files(target, source, env, files=None, path=None): import re import SCons.Util import SCons.Node.FS if files is None: return 0 if not SCons.Util.is_List(files): files = [files] if path is None: if 'XGETTEXTPATH' in env: path = env['XGETTEXTPATH'] else: path = [] if not SCons.Util.is_List(path): path = [path] path = SCons.Util.flatten(path) dirs = () for p in path: if not isinstance(p, SCons.Node.FS.Base): if SCons.Util.is_String(p): p = env.subst(p, source=source, target=target) p = env.arg2nodes(p, env.fs.Dir) dirs += tuple(p) if not dirs: dirs = (env.fs.getcwd(),) re_comment = re.compile(r'^ re_emptyln = re.compile(r'^[ \t\r]*$\r?\n?', re.M) re_trailws = re.compile(r'[ \t\r]+$') for f in files: if isinstance(f, SCons.Node.FS.Base) and f.rexists(): contents = f.get_text_contents() contents = re_comment.sub("", contents) contents = re_emptyln.sub("", contents) contents = re_trailws.sub("", contents) depnames = contents.splitlines() for depname in depnames: depfile = SCons.Node.FS.find_file(depname, dirs) if not depfile: depfile = env.arg2nodes(depname, dirs[0].File) env.Depends(target, depfile) return 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_wxsfile_file_section'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'NAME'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'VERSION'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'VENDOR'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'filename_set'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'id_set'},{'id': '11', 'type': 'block', 'children': ['12', '23', '30', '36', '216']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'create_default_directory_layout'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19', '20', '21', '22']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'NAME'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'VERSION'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'VENDOR'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'filename_set'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'create_feature_dict'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'Document'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'function_definition', 'children': ['37', '38', '41']},{'id': '37', 'type': 'function_name', 'children': [], 'value': 'get_directory'},{'id': '38', 'type': 'parameters', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '41', 'type': 'block', 'children': ['42', '52', '56', '69', '73', '85', '146', '214']},{'id': '42', 'type': 'if_statement', 'children': ['43', '49']},{'id': '43', 'type': 'boolean_operator', 'children': ['44', '47'], 'value': 'or'},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '=='},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '46', 'type': 'string', 'children': [], 'value': "''"},{'id': '47', 'type': 'not_operator', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'Directory'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'dir_parts'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'upper_dir'},{'id': '72', 'type': 'string', 'children': [], 'value': "''"},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dir_parts'},{'id': '76', 'type': 'list_comprehension', 'children': ['77', '78', '81']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '78', 'type': 'for_in_clause', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dir_parts'},{'id': '81', 'type': 'if_clause', 'children': ['82']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '!='},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '84', 'type': 'string', 'children': [], 'value': "''"},{'id': '85', 'type': 'for_statement', 'children': ['86', '87', '91']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dir_parts'},{'id': '89', 'type': 'slice', 'children': ['90']},{'id': '90', 'type': 'colon', 'children': []},{'id': '91', 'type': 'block', 'children': ['92', '121']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'already_created'},{'id': '95', 'type': 'list_comprehension', 'children': ['96', '97', '102']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '97', 'type': 'for_in_clause', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'Directory'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'childNodes'},{'id': '102', 'type': 'if_clause', 'children': ['103']},{'id': '103', 'type': 'boolean_operator', 'children': ['104', '109'], 'value': 'and'},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '=='},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'nodeName'},{'id': '108', 'type': 'string', 'children': [], 'value': "'Directory'"},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '117'], 'value': '=='},{'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': 'c'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '115', 'type': 'string', 'children': [], 'value': "'LongName'"},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '121', 'type': 'if_statement', 'children': ['122', '125', '143']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '!='},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'already_created'},{'id': '124', 'type': 'list', 'children': [], 'value': '[]'},{'id': '125', 'type': 'block', 'children': ['126', '132', '139']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'Directory'},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'already_created'},{'id': '131', 'type': 'integer', 'children': [], 'value': '0'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'dir_parts'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'augmented_assignment', 'children': ['141', '142'], 'value': '+='},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'upper_dir'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '143', 'type': 'else_clause', 'children': ['144']},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'break_statement', 'children': []},{'id': '146', 'type': 'for_statement', 'children': ['147', '148', '149']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dir_parts'},{'id': '149', 'type': 'block', 'children': ['150', '159', '170', '185', '189', '201', '210']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'nDirectory'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'createElement'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'string', 'children': [], 'value': "'Directory'"},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '166']},{'id': '161', 'type': 'subscript', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'nDirectory'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '165', 'type': 'string', 'children': [], 'value': "'LongName'"},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '177']},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'nDirectory'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '176', 'type': 'string', 'children': [], 'value': "'Name'"},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'gen_dos_short_file_name'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'filename_set'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'augmented_assignment', 'children': ['187', '188'], 'value': '+='},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'upper_dir'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'd'},{'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': 'nDirectory'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '195', 'type': 'string', 'children': [], 'value': "'Id'"},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'convert_to_id'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'upper_dir'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'id_set'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '208']},{'id': '203', 'type': 'attribute', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'Directory'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'childNodes'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'nDirectory'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'Directory'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'nDirectory'},{'id': '214', 'type': 'return_statement', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'Directory'},{'id': '216', 'type': 'for_statement', 'children': ['217', '218', '219']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '219', 'type': 'block', 'children': ['220', '235', '246', '257', '288', '320', '329', '342', '355', '368', '381', '394', '403', '411', '423', '431', '440']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '225']},{'id': '222', 'type': 'pattern_list', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'drive'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '225', 'type': 'call', 'children': ['226', '231']},{'id': '226', 'type': 'attribute', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'splitdrive'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'PACKAGING_INSTALL_LOCATION'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '238', 'type': 'call', 'children': ['239', '244']},{'id': '239', 'type': 'attribute', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '249', 'type': 'call', 'children': ['250', '255']},{'id': '250', 'type': 'attribute', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '260', 'type': 'dictionary', 'children': ['261', '264', '271', '274', '281']},{'id': '261', 'type': 'pair', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': "'PACKAGING_X_MSI_VITAL'"},{'id': '263', 'type': 'string', 'children': [], 'value': "'yes'"},{'id': '264', 'type': 'pair', 'children': ['265', '266']},{'id': '265', 'type': 'string', 'children': [], 'value': "'PACKAGING_X_MSI_FILEID'"},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'convert_to_id'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'id_set'},{'id': '271', 'type': 'pair', 'children': ['272', '273']},{'id': '272', 'type': 'string', 'children': [], 'value': "'PACKAGING_X_MSI_LONGNAME'"},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '274', 'type': 'pair', 'children': ['275', '276']},{'id': '275', 'type': 'string', 'children': [], 'value': "'PACKAGING_X_MSI_SHORTNAME'"},{'id': '276', 'type': 'call', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'gen_dos_short_file_name'},{'id': '278', 'type': 'argument_list', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'filename_set'},{'id': '281', 'type': 'pair', 'children': ['282', '283']},{'id': '282', 'type': 'string', 'children': [], 'value': "'PACKAGING_X_MSI_SOURCE'"},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'get_path'},{'id': '287', 'type': 'argument_list', 'children': []},{'id': '288', 'type': 'for_statement', 'children': ['289', '292', '312']},{'id': '289', 'type': 'pattern_list', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '292', 'type': 'list_comprehension', 'children': ['293', '296', '305']},{'id': '293', 'type': 'tuple', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '296', 'type': 'for_in_clause', 'children': ['297', '300']},{'id': '297', 'type': 'tuple_pattern', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '304', 'type': 'argument_list', 'children': []},{'id': '305', 'type': 'if_clause', 'children': ['306']},{'id': '306', 'type': 'not_operator', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '312', 'type': 'block', 'children': ['313']},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '316', 'type': 'argument_list', 'children': ['317', '318', '319']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'assignment', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '323', 'type': 'call', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'createElement'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'string', 'children': [], 'value': "'File'"},{'id': '329', 'type': 'expression_statement', 'children': ['330']},{'id': '330', 'type': 'assignment', 'children': ['331', '336']},{'id': '331', 'type': 'subscript', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '335', 'type': 'string', 'children': [], 'value': "'LongName'"},{'id': '336', 'type': 'call', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'PACKAGING_X_MSI_LONGNAME'},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'assignment', 'children': ['344', '349']},{'id': '344', 'type': 'subscript', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '348', 'type': 'string', 'children': [], 'value': "'Name'"},{'id': '349', 'type': 'call', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'PACKAGING_X_MSI_SHORTNAME'},{'id': '355', 'type': 'expression_statement', 'children': ['356']},{'id': '356', 'type': 'assignment', 'children': ['357', '362']},{'id': '357', 'type': 'subscript', 'children': ['358', '361']},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '361', 'type': 'string', 'children': [], 'value': "'Source'"},{'id': '362', 'type': 'call', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'attribute', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'PACKAGING_X_MSI_SOURCE'},{'id': '368', 'type': 'expression_statement', 'children': ['369']},{'id': '369', 'type': 'assignment', 'children': ['370', '375']},{'id': '370', 'type': 'subscript', 'children': ['371', '374']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '374', 'type': 'string', 'children': [], 'value': "'Id'"},{'id': '375', 'type': 'call', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '377', 'type': 'argument_list', 'children': ['378']},{'id': '378', 'type': 'attribute', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'PACKAGING_X_MSI_FILEID'},{'id': '381', 'type': 'expression_statement', 'children': ['382']},{'id': '382', 'type': 'assignment', 'children': ['383', '388']},{'id': '383', 'type': 'subscript', 'children': ['384', '387']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '387', 'type': 'string', 'children': [], 'value': "'Vital'"},{'id': '388', 'type': 'call', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '390', 'type': 'argument_list', 'children': ['391']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'PACKAGING_X_MSI_VITAL'},{'id': '394', 'type': 'expression_statement', 'children': ['395']},{'id': '395', 'type': 'assignment', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'Component'},{'id': '397', 'type': 'call', 'children': ['398', '401']},{'id': '398', 'type': 'attribute', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'factory'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'createElement'},{'id': '401', 'type': 'argument_list', 'children': ['402']},{'id': '402', 'type': 'string', 'children': [], 'value': "'Component'"},{'id': '403', 'type': 'expression_statement', 'children': ['404']},{'id': '404', 'type': 'assignment', 'children': ['405', '410']},{'id': '405', 'type': 'subscript', 'children': ['406', '409']},{'id': '406', 'type': 'attribute', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'Component'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '409', 'type': 'string', 'children': [], 'value': "'DiskId'"},{'id': '410', 'type': 'string', 'children': [], 'value': "'1'"},{'id': '411', 'type': 'expression_statement', 'children': ['412']},{'id': '412', 'type': 'assignment', 'children': ['413', '418']},{'id': '413', 'type': 'subscript', 'children': ['414', '417']},{'id': '414', 'type': 'attribute', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'Component'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '417', 'type': 'string', 'children': [], 'value': "'Id'"},{'id': '418', 'type': 'call', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'convert_to_id'},{'id': '420', 'type': 'argument_list', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'id_set'},{'id': '423', 'type': 'expression_statement', 'children': ['424']},{'id': '424', 'type': 'assignment', 'children': ['425', '426']},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'Directory'},{'id': '426', 'type': 'call', 'children': ['427', '428']},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'get_directory'},{'id': '428', 'type': 'argument_list', 'children': ['429', '430']},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '431', 'type': 'expression_statement', 'children': ['432']},{'id': '432', 'type': 'call', 'children': ['433', '438']},{'id': '433', 'type': 'attribute', 'children': ['434', '437']},{'id': '434', 'type': 'attribute', 'children': ['435', '436']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'Directory'},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'childNodes'},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '438', 'type': 'argument_list', 'children': ['439']},{'id': '439', 'type': 'identifier', 'children': [], 'value': 'Component'},{'id': '440', 'type': 'expression_statement', 'children': ['441']},{'id': '441', 'type': 'call', 'children': ['442', '447']},{'id': '442', 'type': 'attribute', 'children': ['443', '446']},{'id': '443', 'type': 'attribute', 'children': ['444', '445']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'Component'},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'childNodes'},{'id': '446', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '447', 'type': 'argument_list', 'children': ['448']},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'File'}
def build_wxsfile_file_section(root, files, NAME, VERSION, VENDOR, filename_set, id_set): root = create_default_directory_layout( root, NAME, VERSION, VENDOR, filename_set ) components = create_feature_dict( files ) factory = Document() def get_directory( node, dir ): if dir == '' or not dir: return node Directory = node dir_parts = dir.split(os.path.sep) upper_dir = '' dir_parts = [d for d in dir_parts if d != ''] for d in dir_parts[:]: already_created = [c for c in Directory.childNodes if c.nodeName == 'Directory' and c.attributes['LongName'].value == escape(d)] if already_created != []: Directory = already_created[0] dir_parts.remove(d) upper_dir += d else: break for d in dir_parts: nDirectory = factory.createElement( 'Directory' ) nDirectory.attributes['LongName'] = escape( d ) nDirectory.attributes['Name'] = escape( gen_dos_short_file_name( d, filename_set ) ) upper_dir += d nDirectory.attributes['Id'] = convert_to_id( upper_dir, id_set ) Directory.childNodes.append( nDirectory ) Directory = nDirectory return Directory for file in files: drive, path = os.path.splitdrive( file.PACKAGING_INSTALL_LOCATION ) filename = os.path.basename( path ) dirname = os.path.dirname( path ) h = { 'PACKAGING_X_MSI_VITAL' : 'yes', 'PACKAGING_X_MSI_FILEID' : convert_to_id(filename, id_set), 'PACKAGING_X_MSI_LONGNAME' : filename, 'PACKAGING_X_MSI_SHORTNAME' : gen_dos_short_file_name(filename, filename_set), 'PACKAGING_X_MSI_SOURCE' : file.get_path(), } for k,v in [ (k, v) for (k,v) in h.items() if not hasattr(file, k) ]: setattr( file, k, v ) File = factory.createElement( 'File' ) File.attributes['LongName'] = escape( file.PACKAGING_X_MSI_LONGNAME ) File.attributes['Name'] = escape( file.PACKAGING_X_MSI_SHORTNAME ) File.attributes['Source'] = escape( file.PACKAGING_X_MSI_SOURCE ) File.attributes['Id'] = escape( file.PACKAGING_X_MSI_FILEID ) File.attributes['Vital'] = escape( file.PACKAGING_X_MSI_VITAL ) Component = factory.createElement('Component') Component.attributes['DiskId'] = '1' Component.attributes['Id'] = convert_to_id( filename, id_set ) Directory = get_directory( root, dirname ) Directory.childNodes.append( Component ) Component.childNodes.append( File )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'FromReadings'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '13', '16', '19', '22']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'readings'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'report_id'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'IOTileReading'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'InvalidReadingID'},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0xFFFF'},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '18', 'type': 'integer', 'children': [], 'value': '0x100'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sent_timestamp'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'received_time'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '32', '38', '102', '114', '126', '162', '177']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'lowest_id'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'IOTileReading'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'InvalidReadingID'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'highest_id'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'IOTileReading'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'InvalidReadingID'},{'id': '38', 'type': 'for_statement', 'children': ['39', '40', '53']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '44', 'type': 'argument_list', 'children': ['45', '49']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'readings'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '53', 'type': 'block', 'children': ['54', '64', '83']},{'id': '54', 'type': 'if_statement', 'children': ['55', '62']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '59'], 'value': '=='},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'reading_id'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'IOTileReading'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'InvalidReadingID'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'continue_statement', 'children': []},{'id': '64', 'type': 'if_statement', 'children': ['65', '76']},{'id': '65', 'type': 'boolean_operator', 'children': ['66', '71'], 'value': 'or'},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '=='},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'lowest_id'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'IOTileReading'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'InvalidReadingID'},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': '<'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'reading_id'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'lowest_id'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'lowest_id'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'reading_id'},{'id': '83', 'type': 'if_statement', 'children': ['84', '95']},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '90'], 'value': 'or'},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': '=='},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'highest_id'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'IOTileReading'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'InvalidReadingID'},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': '>'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'reading_id'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'highest_id'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'highest_id'},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'reading_id'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'reading_list'},{'id': '105', 'type': 'list_comprehension', 'children': ['106', '111']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'asdict'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'for_in_clause', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'readings'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'event_list'},{'id': '117', 'type': 'list_comprehension', 'children': ['118', '123']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'asdict'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'for_in_clause', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'report_dict'},{'id': '129', 'type': 'dictionary', 'children': ['130', '135', '138', '141', '144', '147', '150', '153', '156', '159']},{'id': '130', 'type': 'pair', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': '"format"'},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'FORMAT_TAG'},{'id': '135', 'type': 'pair', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': '"device"'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '138', 'type': 'pair', 'children': ['139', '140']},{'id': '139', 'type': 'string', 'children': [], 'value': '"streamer_index"'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '141', 'type': 'pair', 'children': ['142', '143']},{'id': '142', 'type': 'string', 'children': [], 'value': '"streamer_selector"'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '144', 'type': 'pair', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': '"incremental_id"'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'report_id'},{'id': '147', 'type': 'pair', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': '"lowest_id"'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'lowest_id'},{'id': '150', 'type': 'pair', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': '"highest_id"'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'highest_id'},{'id': '153', 'type': 'pair', 'children': ['154', '155']},{'id': '154', 'type': 'string', 'children': [], 'value': '"device_sent_timestamp"'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'sent_timestamp'},{'id': '156', 'type': 'pair', 'children': ['157', '158']},{'id': '157', 'type': 'string', 'children': [], 'value': '"events"'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'event_list'},{'id': '159', 'type': 'pair', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': '"data"'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'reading_list'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'encoded'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'msgpack'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'packb'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171', '174']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'report_dict'},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '173', 'type': 'identifier', 'children': [], 'value': '_encode_datetime'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'use_bin_type'},{'id': '176', 'type': 'True', 'children': []},{'id': '177', 'type': 'return_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'FlexibleDictionaryReport'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182', '185', '188']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'encoded'},{'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'signed'},{'id': '184', 'type': 'False', 'children': []},{'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'encrypted'},{'id': '187', 'type': 'False', 'children': []},{'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'received_time'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'received_time'}
def FromReadings(cls, uuid, readings, events, report_id=IOTileReading.InvalidReadingID, selector=0xFFFF, streamer=0x100, sent_timestamp=0, received_time=None): lowest_id = IOTileReading.InvalidReadingID highest_id = IOTileReading.InvalidReadingID for item in itertools.chain(iter(readings), iter(events)): if item.reading_id == IOTileReading.InvalidReadingID: continue if lowest_id == IOTileReading.InvalidReadingID or item.reading_id < lowest_id: lowest_id = item.reading_id if highest_id == IOTileReading.InvalidReadingID or item.reading_id > highest_id: highest_id = item.reading_id reading_list = [x.asdict() for x in readings] event_list = [x.asdict() for x in events] report_dict = { "format": cls.FORMAT_TAG, "device": uuid, "streamer_index": streamer, "streamer_selector": selector, "incremental_id": report_id, "lowest_id": lowest_id, "highest_id": highest_id, "device_sent_timestamp": sent_timestamp, "events": event_list, "data": reading_list } encoded = msgpack.packb(report_dict, default=_encode_datetime, use_bin_type=True) return FlexibleDictionaryReport(encoded, signed=False, encrypted=False, received_time=received_time)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_object_instance_content'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'block', 'children': ['6', '12', '19', '39', '45', '57', '69', '88', '138', '144', '165', '173', '195', '201', '205', '227', '234', '241', '248', '255', '262', '269', '276', '291', '298', '305', '312']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "b'N.'"},{'id': '19', 'type': 'if_statement', 'children': ['20', '29']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'BaseStringTypes'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'return_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': 'SCons'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'to_bytes'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'inst_class'},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'inst_class_name'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '50', 'type': 'argument_list', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '56', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'inst_class_module'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '62', 'type': 'argument_list', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '68', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'inst_class_hierarchy'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '74', 'type': 'argument_list', 'children': ['75', '87']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'getclasstree'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'list', 'children': ['84'], 'value': '[obj.__class__,]'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '86', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '87', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '91', 'type': 'list_comprehension', 'children': ['92', '100', '106']},{'id': '92', 'type': 'tuple', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98', '99']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '99', 'type': 'string', 'children': [], 'value': '"None"'},{'id': '100', 'type': 'for_in_clause', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '106', 'type': 'if_clause', 'children': ['107']},{'id': '107', 'type': 'not_operator', 'children': ['108']},{'id': '108', 'type': '()', 'children': ['109']},{'id': '109', 'type': 'boolean_operator', 'children': ['110', '128'], 'value': 'or'},{'id': '110', 'type': 'boolean_operator', 'children': ['111', '118'], 'value': 'or'},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '117'], 'value': '=='},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '114', 'type': 'slice', 'children': ['115', '116']},{'id': '115', 'type': 'colon', 'children': []},{'id': '116', 'type': 'integer', 'children': [], 'value': '2'},{'id': '117', 'type': 'string', 'children': [], 'value': "'__'"},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ismethod'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'isbuiltin'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '143', 'type': 'argument_list', 'children': []},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'properties_str'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'string', 'children': [], 'value': "','"},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'list_comprehension', 'children': ['153', '162']},{'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '%'},{'id': '154', 'type': 'string', 'children': [], 'value': '"%s=%s"'},{'id': '155', 'type': 'tuple', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '158', 'type': 'integer', 'children': [], 'value': '0'},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'for_in_clause', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'properties_bytes'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'properties_str'},{'id': '172', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'methods'},{'id': '176', 'type': 'list_comprehension', 'children': ['177', '178', '184']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '178', 'type': 'for_in_clause', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '184', 'type': 'if_clause', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'ismethod'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '192', 'type': 'argument_list', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'methods'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '200', 'type': 'argument_list', 'children': []},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'method_contents'},{'id': '204', 'type': 'list', 'children': [], 'value': '[]'},{'id': '205', 'type': 'for_statement', 'children': ['206', '207', '208']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'methods'},{'id': '208', 'type': 'block', 'children': ['209', '220']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': '_function_contents'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '217', 'type': 'argument_list', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'method_contents'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'string', 'children': [], 'value': "b'{'"},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'inst_class_name'},{'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': 'retval'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'string', 'children': [], 'value': 'b":"'},{'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': 'retval'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'inst_class_module'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'string', 'children': [], 'value': "b'}[['"},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'inst_class_hierarchy'},{'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': 'retval'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'string', 'children': [], 'value': "b']]{{'"},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '289']},{'id': '283', 'type': 'attribute', 'children': ['284', '288']},{'id': '284', 'type': 'call', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'string', 'children': [], 'value': 'b","'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'method_contents'},{'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': 'retval'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'string', 'children': [], 'value': 'b"}}{{{"'},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'properties_bytes'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'string', 'children': [], 'value': "b'}}}'"},{'id': '312', 'type': 'return_statement', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'retval'}
def _object_instance_content(obj): retval = bytearray() if obj is None: return b'N.' if isinstance(obj, SCons.Util.BaseStringTypes): return SCons.Util.to_bytes(obj) inst_class = obj.__class__ inst_class_name = bytearray(obj.__class__.__name__,'utf-8') inst_class_module = bytearray(obj.__class__.__module__,'utf-8') inst_class_hierarchy = bytearray(repr(inspect.getclasstree([obj.__class__,])),'utf-8') properties = [(p, getattr(obj, p, "None")) for p in dir(obj) if not (p[:2] == '__' or inspect.ismethod(getattr(obj, p)) or inspect.isbuiltin(getattr(obj,p))) ] properties.sort() properties_str = ','.join(["%s=%s"%(p[0],p[1]) for p in properties]) properties_bytes = bytearray(properties_str,'utf-8') methods = [p for p in dir(obj) if inspect.ismethod(getattr(obj, p))] methods.sort() method_contents = [] for m in methods: v = _function_contents(getattr(obj, m)) method_contents.append(v) retval = bytearray(b'{') retval.extend(inst_class_name) retval.extend(b":") retval.extend(inst_class_module) retval.extend(b'}[[') retval.extend(inst_class_hierarchy) retval.extend(b']]{{') retval.extend(bytearray(b",").join(method_contents)) retval.extend(b"}}{{{") retval.extend(properties_bytes) retval.extend(b'}}}') return retval
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'execute'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '20', '28', '48', '94', '107', '114', '172', '191', '213', '274']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'escape_list'},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Subst'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'escape_list'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'flatten_sequence'},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'flatten_sequence'},{'id': '28', 'type': 'try_statement', 'children': ['29', '36']},{'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': 'shell'},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '35', 'type': 'string', 'children': [], 'value': "'SHELL'"},{'id': '36', 'type': 'except_clause', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'raise_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'Errors'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'UserError'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': "'Missing SHELL construction variable.'"},{'id': '48', 'type': 'try_statement', 'children': ['49', '56', '68']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'spawn'},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '55', 'type': 'string', 'children': [], 'value': "'SPAWN'"},{'id': '56', 'type': 'except_clause', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'raise_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '66']},{'id': '61', 'type': 'attribute', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'Errors'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'UserError'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': "'Missing SPAWN construction variable.'"},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'if_statement', 'children': ['71', '75']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'is_String'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'spawn'},{'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': 'spawn'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '88']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'spawn'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'raw'},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'conv'},{'id': '90', 'type': 'lambda', 'children': ['91', '93']},{'id': '91', 'type': 'lambda_parameters', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'ESCAPE'"},{'id': '103', 'type': 'lambda', 'children': ['104', '106']},{'id': '104', 'type': 'lambda_parameters', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ENV'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'get_default_ENV'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '114', 'type': 'for_statement', 'children': ['115', '118', '123']},{'id': '115', 'type': 'pattern_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ENV'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'if_statement', 'children': ['125', '130']},{'id': '125', 'type': 'not_operator', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'is_String'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'if_statement', 'children': ['132', '136', '161']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'is_List'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '136', 'type': 'block', 'children': ['137', '144']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'flatten_sequence'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '149']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'ENV'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '149', 'type': 'call', 'children': ['150', '155']},{'id': '150', 'type': 'attribute', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'pathsep'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '160', 'type': 'identifier', 'children': [], 'value': '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', '168']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'ENV'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '172', 'type': 'if_statement', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '174', 'type': 'block', 'children': ['175', '183']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'get_all_targets'},{'id': '182', 'type': 'argument_list', 'children': []},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'get_all_sources'},{'id': '190', 'type': 'argument_list', 'children': []},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '197']},{'id': '193', 'type': 'pattern_list', 'children': ['194', '195', '196']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'cmd_list'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'ignore'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'silent'},{'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': 'process'},{'id': '201', 'type': 'argument_list', 'children': ['202', '203', '211', '212']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'rfile'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'executor'},{'id': '213', 'type': 'for_statement', 'children': ['214', '215', '220']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'cmd_line'},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '217', 'type': 'argument_list', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'cmd_list'},{'id': '220', 'type': 'block', 'children': ['221', '229', '242']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'cmd_line'},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'escape_list'},{'id': '226', 'type': 'argument_list', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'cmd_line'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'spawn'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236', '237', '240', '241']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'cmd_line'},{'id': '239', 'type': 'integer', 'children': [], 'value': '0'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'cmd_line'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'ENV'},{'id': '242', 'type': 'if_statement', 'children': ['243', '247']},{'id': '243', 'type': 'boolean_operator', 'children': ['244', '246'], 'value': 'and'},{'id': '244', 'type': 'not_operator', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'ignore'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '247', 'type': 'block', 'children': ['248', '254']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '251', 'type': 'binary_operator', 'children': ['252', '253'], 'value': '%'},{'id': '252', 'type': 'string', 'children': [], 'value': '"Error %s"'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '254', 'type': 'return_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '261']},{'id': '256', 'type': 'attribute', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'Errors'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'BuildError'},{'id': '261', 'type': 'argument_list', 'children': ['262', '265', '268', '271']},{'id': '262', 'type': 'keyword_argument', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'errstr'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'cmd_line'},{'id': '274', 'type': 'return_statement', 'children': ['275']},{'id': '275', 'type': 'integer', 'children': [], 'value': '0'}
def execute(self, target, source, env, executor=None): escape_list = SCons.Subst.escape_list flatten_sequence = SCons.Util.flatten_sequence try: shell = env['SHELL'] except KeyError: raise SCons.Errors.UserError('Missing SHELL construction variable.') try: spawn = env['SPAWN'] except KeyError: raise SCons.Errors.UserError('Missing SPAWN construction variable.') else: if is_String(spawn): spawn = env.subst(spawn, raw=1, conv=lambda x: x) escape = env.get('ESCAPE', lambda x: x) ENV = get_default_ENV(env) for key, value in ENV.items(): if not is_String(value): if is_List(value): value = flatten_sequence(value) ENV[key] = os.pathsep.join(map(str, value)) else: ENV[key] = str(value) if executor: target = executor.get_all_targets() source = executor.get_all_sources() cmd_list, ignore, silent = self.process(target, list(map(rfile, source)), env, executor) for cmd_line in filter(len, cmd_list): cmd_line = escape_list(cmd_line, escape) result = spawn(shell, escape, cmd_line[0], cmd_line, ENV) if not ignore and result: msg = "Error %s" % result return SCons.Errors.BuildError(errstr=msg, status=result, action=self, command=cmd_line) return 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_try_load_module'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'import_name'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '18', '22', '50', '63', '72', '95', '108', '124', '143']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'obj_name'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'if_statement', 'children': ['23', '37']},{'id': '23', 'type': 'boolean_operator', 'children': ['24', '30'], 'value': 'and'},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '29'], 'value': '>'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '29', 'type': 'integer', 'children': [], 'value': '2'},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'in'},{'id': '31', 'type': 'string', 'children': [], 'value': "':'"},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '34', 'type': 'slice', 'children': ['35', '36']},{'id': '35', 'type': 'integer', 'children': [], 'value': '2'},{'id': '36', 'type': 'colon', 'children': []},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '44']},{'id': '40', 'type': 'pattern_list', 'children': ['41', '42', '43']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'obj_name'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'rpartition'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': '":"'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '55']},{'id': '52', 'type': 'pattern_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'basename'},{'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': 'os'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '63', 'type': 'if_statement', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '=='},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '66', 'type': 'string', 'children': [], 'value': "''"},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '71', 'type': 'string', 'children': [], 'value': "'./'"},{'id': '72', 'type': 'if_statement', 'children': ['73', '86']},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '77'], 'value': 'or'},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': '=='},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '76', 'type': 'string', 'children': [], 'value': "''"},{'id': '77', 'type': 'not_operator', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '84']},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'raise_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ArgumentError'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': '"Could not find python module to load extension"'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '100']},{'id': '97', 'type': 'pattern_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '100', 'type': 'call', 'children': ['101', '106']},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '108', 'type': 'if_statement', 'children': ['109', '115']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'not'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '111', 'type': 'tuple', 'children': ['112', '113', '114']},{'id': '112', 'type': 'string', 'children': [], 'value': '".py"'},{'id': '113', 'type': 'string', 'children': [], 'value': '".pyc"'},{'id': '114', 'type': 'string', 'children': [], 'value': '""'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'raise_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'ArgumentError'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'string', 'children': [], 'value': '"Attempted to load module is not a python package or module (.py or .pyc)"'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '124', 'type': 'if_statement', 'children': ['125', '128', '133']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'import_name'},{'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': 'import_name'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': '"Importing module as subpackage: %s"'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'import_name'},{'id': '143', 'type': 'try_statement', 'children': ['144', '228']},{'id': '144', 'type': 'block', 'children': ['145', '149', '163', '192', '224']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'fileobj'},{'id': '148', 'type': 'None', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '155']},{'id': '151', 'type': 'pattern_list', 'children': ['152', '153', '154']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'fileobj'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'pathname'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'imp'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'find_module'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '161', 'type': 'list', 'children': ['162'], 'value': '[folder]'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '163', 'type': 'if_statement', 'children': ['164', '169', '178']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'in'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '173', 'type': 'subscript', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '178', 'type': 'else_clause', 'children': ['179']},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'imp'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'load_module'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189', '190', '191']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'import_name'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'fileobj'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'pathname'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '192', 'type': 'if_statement', 'children': ['193', '196']},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': 'is'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'obj_name'},{'id': '195', 'type': 'None', 'children': []},{'id': '196', 'type': 'block', 'children': ['197', '216']},{'id': '197', 'type': 'if_statement', 'children': ['198', '203']},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': 'not'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'obj_name'},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '202', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'raise_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'ArgumentError'},{'id': '207', 'type': 'argument_list', 'children': ['208', '213']},{'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '%'},{'id': '209', 'type': 'string', 'children': [], 'value': '"Cannot find named object \'%s\' inside module \'%s\'"'},{'id': '210', 'type': 'tuple', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'obj_name'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '219', 'type': 'subscript', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '222', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'obj_name'},{'id': '224', 'type': 'return_statement', 'children': ['225']},{'id': '225', 'type': 'expression_list', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '228', 'type': 'finally_clause', 'children': ['229']},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'if_statement', 'children': ['231', '234']},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': 'is'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'fileobj'},{'id': '233', 'type': 'None', 'children': []},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'fileobj'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '240', 'type': 'argument_list', 'children': []}
def _try_load_module(path, import_name=None): logger = logging.getLogger(__name__) obj_name = None if len(path) > 2 and ':' in path[2:]: path, _, obj_name = path.rpartition(":") folder, basename = os.path.split(path) if folder == '': folder = './' if basename == '' or not os.path.exists(path): raise ArgumentError("Could not find python module to load extension", path=path) basename, ext = os.path.splitext(basename) if ext not in (".py", ".pyc", ""): raise ArgumentError("Attempted to load module is not a python package or module (.py or .pyc)", path=path) if import_name is None: import_name = basename else: logger.debug("Importing module as subpackage: %s", import_name) try: fileobj = None fileobj, pathname, description = imp.find_module(basename, [folder]) if basename in sys.modules: mod = sys.modules[basename] else: mod = imp.load_module(import_name, fileobj, pathname, description) if obj_name is not None: if obj_name not in mod.__dict__: raise ArgumentError("Cannot find named object '%s' inside module '%s'" % (obj_name, basename), path=path) mod = mod.__dict__[obj_name] return basename, mod finally: if fileobj is not None: fileobj.close()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_extensions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'name_filter'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'comp_filter'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'class_filter'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'product_name'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '26', '131', '205', '247', '266', '320']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'found_extensions'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'if_statement', 'children': ['27', '30']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'product_name'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'for_statement', 'children': ['32', '33', '38']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'comp'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'iter_components'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'block', 'children': ['39', '51', '60']},{'id': '39', 'type': 'if_statement', 'children': ['40', '49']},{'id': '40', 'type': 'boolean_operator', 'children': ['41', '44'], 'value': 'and'},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'comp_filter'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': '!='},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'comp'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'comp_filter'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'continue_statement', 'children': []},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'products'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'comp'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'find_products'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'product_name'},{'id': '60', 'type': 'for_statement', 'children': ['61', '62', '63']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'products'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'try_statement', 'children': ['65', '117']},{'id': '65', 'type': 'block', 'children': ['66', '84', '110']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'load_extension'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '78', '81']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'name_filter'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'name_filter'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'class_filter'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'class_filter'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'comp'},{'id': '84', 'type': 'if_statement', 'children': ['85', '95']},{'id': '85', 'type': 'boolean_operator', 'children': ['86', '92'], 'value': 'and'},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '91'], 'value': '=='},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'is'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'name_filter'},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'block', 'children': ['96', '109']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105', '106']},{'id': '104', 'type': 'string', 'children': [], 'value': '"Found no valid extensions in product %s of component %s"'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'comp'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '109', 'type': 'continue_statement', 'children': []},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'found_extensions'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '117', 'type': 'except_clause', 'children': ['118']},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128', '129', '130']},{'id': '127', 'type': 'string', 'children': [], 'value': '"Unable to load extension %s from local component %s at path %s"'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'product_name'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'comp'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '131', 'type': 'for_statement', 'children': ['132', '133', '139']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_iter_entrypoint_group'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '139', 'type': 'block', 'children': ['140', '146', '156', '187']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '146', 'type': 'if_statement', 'children': ['147', '154']},{'id': '147', 'type': 'boolean_operator', 'children': ['148', '151'], 'value': 'and'},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'is'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'name_filter'},{'id': '150', 'type': 'None', 'children': []},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': '!='},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'name_filter'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'continue_statement', 'children': []},{'id': '156', 'type': 'try_statement', 'children': ['157', '166']},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'except_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168', '186']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '175']},{'id': '170', 'type': 'attribute', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177', '180', '183']},{'id': '176', 'type': 'string', 'children': [], 'value': '"Unable to load %s from %s"'},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'distro'},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '185', 'type': 'True', 'children': []},{'id': '186', 'type': 'continue_statement', 'children': []},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'found_extensions'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '192', 'type': 'generator_expression', 'children': ['193', '196']},{'id': '193', 'type': 'tuple', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '196', 'type': 'for_in_clause', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '201', 'type': 'identifier', 'children': [], 'value': '_filter_subclasses'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'class_filter'},{'id': '205', 'type': 'for_statement', 'children': ['206', '209', '218']},{'id': '206', 'type': 'tuple_pattern', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '209', 'type': 'call', 'children': ['210', '215']},{'id': '210', 'type': 'attribute', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': '_registered_extensions'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '217', 'type': 'list', 'children': [], 'value': '[]'},{'id': '218', 'type': 'block', 'children': ['219', '229']},{'id': '219', 'type': 'if_statement', 'children': ['220', '227']},{'id': '220', 'type': 'boolean_operator', 'children': ['221', '224'], 'value': 'and'},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '223'], 'value': 'is'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'name_filter'},{'id': '223', 'type': 'None', 'children': []},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': '!='},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'name_filter'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'continue_statement', 'children': []},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'found_extensions'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '234', 'type': 'generator_expression', 'children': ['235', '238']},{'id': '235', 'type': 'tuple', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '238', 'type': 'for_in_clause', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '243', 'type': 'identifier', 'children': [], 'value': '_filter_subclasses'},{'id': '244', 'type': 'argument_list', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'class_filter'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'found_extensions'},{'id': '250', 'type': 'list_comprehension', 'children': ['251', '254', '259']},{'id': '251', 'type': 'tuple', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '254', 'type': 'for_in_clause', 'children': ['255', '258']},{'id': '255', 'type': 'pattern_list', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'found_extensions'},{'id': '259', 'type': 'if_clause', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '263', 'type': 'identifier', 'children': [], 'value': '_filter_nonextensions'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '266', 'type': 'if_statement', 'children': ['267', '270']},{'id': '267', 'type': 'comparison_operator', 'children': ['268', '269'], 'value': 'is'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '269', 'type': 'True', 'children': []},{'id': '270', 'type': 'block', 'children': ['271', '316']},{'id': '271', 'type': 'if_statement', 'children': ['272', '278', '297']},{'id': '272', 'type': 'comparison_operator', 'children': ['273', '277'], 'value': '>'},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'found_extensions'},{'id': '277', 'type': 'integer', 'children': [], 'value': '1'},{'id': '278', 'type': 'block', 'children': ['279']},{'id': '279', 'type': 'raise_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'ArgumentError'},{'id': '282', 'type': 'argument_list', 'children': ['283', '294']},{'id': '283', 'type': 'binary_operator', 'children': ['284', '285'], 'value': '%'},{'id': '284', 'type': 'string', 'children': [], 'value': '"Extension %s should have had exactly one instance of class %s, found %d"'},{'id': '285', 'type': 'tuple', 'children': ['286', '287', '290']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'class_filter'},{'id': '289', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'found_extensions'},{'id': '294', 'type': 'keyword_argument', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'found_extensions'},{'id': '297', 'type': 'elif_clause', 'children': ['298', '304']},{'id': '298', 'type': 'comparison_operator', 'children': ['299', '303'], 'value': '=='},{'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': 'found_extensions'},{'id': '303', 'type': 'integer', 'children': [], 'value': '0'},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'raise_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'ArgumentError'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'binary_operator', 'children': ['310', '311'], 'value': '%'},{'id': '310', 'type': 'string', 'children': [], 'value': '"Extension %s had no instances of class %s"'},{'id': '311', 'type': 'tuple', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'class_filter'},{'id': '315', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '316', 'type': 'return_statement', 'children': ['317']},{'id': '317', 'type': 'subscript', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'found_extensions'},{'id': '319', 'type': 'integer', 'children': [], 'value': '0'},{'id': '320', 'type': 'return_statement', 'children': ['321']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'found_extensions'}
def load_extensions(self, group, name_filter=None, comp_filter=None, class_filter=None, product_name=None, unique=False): found_extensions = [] if product_name is not None: for comp in self.iter_components(): if comp_filter is not None and comp.name != comp_filter: continue products = comp.find_products(product_name) for product in products: try: entries = self.load_extension(product, name_filter=name_filter, class_filter=class_filter, component=comp) if len(entries) == 0 and name_filter is None: self._logger.warn("Found no valid extensions in product %s of component %s", product, comp.path) continue found_extensions.extend(entries) except: self._logger.exception("Unable to load extension %s from local component %s at path %s", product_name, comp, product) for entry in self._iter_entrypoint_group(group): name = entry.name if name_filter is not None and name != name_filter: continue try: ext = entry.load() except: self._logger.warn("Unable to load %s from %s", entry.name, entry.distro, exc_info=True) continue found_extensions.extend((name, x) for x in self._filter_subclasses(ext, class_filter)) for (name, ext) in self._registered_extensions.get(group, []): if name_filter is not None and name != name_filter: continue found_extensions.extend((name, x) for x in self._filter_subclasses(ext, class_filter)) found_extensions = [(name, x) for name, x in found_extensions if self._filter_nonextensions(x)] if unique is True: if len(found_extensions) > 1: raise ArgumentError("Extension %s should have had exactly one instance of class %s, found %d" % (group, class_filter.__name__, len(found_extensions)), classes=found_extensions) elif len(found_extensions) == 0: raise ArgumentError("Extension %s had no instances of class %s" % (group, class_filter.__name__)) return found_extensions[0] return found_extensions
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_extension'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'name_filter'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'class_filter'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '23', '36', '48', '59', '75', '94', '100', '145']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'import_name'},{'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': 'component'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'import_name'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_ensure_package_loaded'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '41']},{'id': '38', 'type': 'pattern_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_try_load_module'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'import_name'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'import_name'},{'id': '48', 'type': 'if_statement', 'children': ['49', '56']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '53'], 'value': 'and'},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'name_filter'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '!='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'name_filter'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'list', 'children': [], 'value': '[]'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '62', 'type': 'list_comprehension', 'children': ['63', '66']},{'id': '63', 'type': 'tuple', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_filter_subclasses'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'class_filter'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '78', 'type': 'list_comprehension', 'children': ['79', '82', '87']},{'id': '79', 'type': 'tuple', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '82', 'type': 'for_in_clause', 'children': ['83', '86']},{'id': '83', 'type': 'pattern_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '87', 'type': 'if_clause', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': '_filter_nonextensions'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '94', 'type': 'if_statement', 'children': ['95', '97']},{'id': '95', 'type': 'not_operator', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '100', 'type': 'if_statement', 'children': ['101', '107', '126']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '106'], 'value': '>'},{'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': 'found'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'raise_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'ArgumentError'},{'id': '111', 'type': 'argument_list', 'children': ['112', '123']},{'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '%'},{'id': '113', 'type': 'string', 'children': [], 'value': '"Extension %s should have had exactly one instance of class %s, found %d"'},{'id': '114', 'type': 'tuple', 'children': ['115', '116', '119']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'class_filter'},{'id': '118', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '126', 'type': 'elif_clause', 'children': ['127', '133']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '132'], 'value': '=='},{'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': 'found'},{'id': '132', 'type': 'integer', 'children': [], 'value': '0'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'raise_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'ArgumentError'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '%'},{'id': '139', 'type': 'string', 'children': [], 'value': '"Extension %s had no instances of class %s"'},{'id': '140', 'type': 'tuple', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'class_filter'},{'id': '144', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '145', 'type': 'return_statement', 'children': ['146']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'}
def load_extension(self, path, name_filter=None, class_filter=None, unique=False, component=None): import_name = None if component is not None: import_name = _ensure_package_loaded(path, component) name, ext = _try_load_module(path, import_name=import_name) if name_filter is not None and name != name_filter: return [] found = [(name, x) for x in self._filter_subclasses(ext, class_filter)] found = [(name, x) for name, x in found if self._filter_nonextensions(x)] if not unique: return found if len(found) > 1: raise ArgumentError("Extension %s should have had exactly one instance of class %s, found %d" % (path, class_filter.__name__, len(found)), classes=found) elif len(found) == 0: raise ArgumentError("Extension %s had no instances of class %s" % (path, class_filter.__name__)) return found[0]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'solutionEmitter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '7', 'type': 'block', 'children': ['8', '21', '39', '48', '56', '326']},{'id': '8', 'type': 'if_statement', 'children': ['9', '16']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': '=='},{'id': '10', 'type': 'subscript', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '12', 'type': 'integer', 'children': [], 'value': '0'},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '20', 'type': 'list', 'children': [], 'value': '[]'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '26']},{'id': '23', 'type': 'tuple_pattern', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'suff'},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'suff'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': "'$MSVSSOLUTIONSUFFIX'"},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '53']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '+'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'suff'},{'id': '56', 'type': 'if_statement', 'children': ['57', '59']},{'id': '57', 'type': 'not_operator', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '59', 'type': 'block', 'children': ['60', '64', '102', '198', '236', '299', '312']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '63', 'type': 'string', 'children': [], 'value': "'sln_inputs:'"},{'id': '64', 'type': 'if_statement', 'children': ['65', '68']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'in'},{'id': '66', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'if_statement', 'children': ['70', '80', '91']},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'is_String'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '79', 'type': 'string', 'children': [], 'value': "'name'"},{'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': 'source'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '+'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '%'},{'id': '87', 'type': 'string', 'children': [], 'value': '\' "%s"\''},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '90', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '91', 'type': 'else_clause', 'children': ['92']},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'raise_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'Errors'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'InternalError'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'string', 'children': [], 'value': '"name must be a string"'},{'id': '102', 'type': 'if_statement', 'children': ['103', '106', '187']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'in'},{'id': '104', 'type': 'string', 'children': [], 'value': "'variant'"},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'if_statement', 'children': ['108', '118', '129', '176']},{'id': '108', 'type': 'call', 'children': ['109', '114']},{'id': '109', 'type': 'attribute', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'is_String'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '117', 'type': 'string', 'children': [], 'value': "'variant'"},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '+'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '%'},{'id': '125', 'type': 'string', 'children': [], 'value': '\' "%s"\''},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '128', 'type': 'string', 'children': [], 'value': "'variant'"},{'id': '129', 'type': 'elif_clause', 'children': ['130', '140']},{'id': '130', 'type': 'call', 'children': ['131', '136']},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'is_List'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '139', 'type': 'string', 'children': [], 'value': "'variant'"},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'for_statement', 'children': ['142', '143', '146']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '145', 'type': 'string', 'children': [], 'value': "'variant'"},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'if_statement', 'children': ['148', '156', '165']},{'id': '148', 'type': 'call', 'children': ['149', '154']},{'id': '149', 'type': 'attribute', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'is_String'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'variant'},{'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': 'source'},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '+'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '%'},{'id': '163', 'type': 'string', 'children': [], 'value': '\' "%s"\''},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '165', 'type': 'else_clause', 'children': ['166']},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'raise_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '174']},{'id': '169', 'type': 'attribute', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'Errors'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'InternalError'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'string', 'children': [], 'value': '"name must be a string or a list of strings"'},{'id': '176', 'type': 'else_clause', 'children': ['177']},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'raise_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': 'SCons'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'Errors'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'InternalError'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'string', 'children': [], 'value': '"variant must be a string or a list of strings"'},{'id': '187', 'type': 'else_clause', 'children': ['188']},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'raise_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '196']},{'id': '191', 'type': 'attribute', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'Errors'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'InternalError'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'string', 'children': [], 'value': '"variant must be specified"'},{'id': '198', 'type': 'if_statement', 'children': ['199', '202']},{'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': 'in'},{'id': '200', 'type': 'string', 'children': [], 'value': "'slnguid'"},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'if_statement', 'children': ['204', '214', '225']},{'id': '204', 'type': 'call', 'children': ['205', '210']},{'id': '205', 'type': 'attribute', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'is_String'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '213', 'type': 'string', 'children': [], 'value': "'slnguid'"},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '220', 'type': 'binary_operator', 'children': ['221', '222'], 'value': '%'},{'id': '221', 'type': 'string', 'children': [], 'value': '\' "%s"\''},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '224', 'type': 'string', 'children': [], 'value': "'slnguid'"},{'id': '225', 'type': 'else_clause', 'children': ['226']},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'raise_statement', 'children': ['228']},{'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': 'SCons'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'Errors'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'InternalError'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'string', 'children': [], 'value': '"slnguid must be a string"'},{'id': '236', 'type': 'if_statement', 'children': ['237', '240']},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': 'in'},{'id': '238', 'type': 'string', 'children': [], 'value': "'projects'"},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'if_statement', 'children': ['242', '252', '263']},{'id': '242', 'type': 'call', 'children': ['243', '248']},{'id': '243', 'type': 'attribute', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'is_String'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '251', 'type': 'string', 'children': [], 'value': "'projects'"},{'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': 'source'},{'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '+'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '258', 'type': 'binary_operator', 'children': ['259', '260'], 'value': '%'},{'id': '259', 'type': 'string', 'children': [], 'value': '\' "%s"\''},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '262', 'type': 'string', 'children': [], 'value': "'projects'"},{'id': '263', 'type': 'elif_clause', 'children': ['264', '274']},{'id': '264', 'type': 'call', 'children': ['265', '270']},{'id': '265', 'type': 'attribute', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'is_List'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '273', 'type': 'string', 'children': [], 'value': "'projects'"},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'for_statement', 'children': ['276', '277', '280']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '277', 'type': 'subscript', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '279', 'type': 'string', 'children': [], 'value': "'projects'"},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'if_statement', 'children': ['282', '290']},{'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': 'SCons'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'is_String'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '290', 'type': 'block', 'children': ['291']},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '294', 'type': 'binary_operator', 'children': ['295', '296'], 'value': '+'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '296', 'type': 'binary_operator', 'children': ['297', '298'], 'value': '%'},{'id': '297', 'type': 'string', 'children': [], 'value': '\' "%s"\''},{'id': '298', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '302', 'type': 'binary_operator', 'children': ['303', '304'], 'value': '+'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '304', 'type': 'binary_operator', 'children': ['305', '306'], 'value': '%'},{'id': '305', 'type': 'string', 'children': [], 'value': '\' "%s"\''},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'subscript', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '311', 'type': 'integer', 'children': [], 'value': '0'},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '315', 'type': 'list', 'children': ['316'], 'value': '[SCons.Node.Python.Value(source)]'},{'id': '316', 'type': 'call', 'children': ['317', '324']},{'id': '317', 'type': 'attribute', 'children': ['318', '323']},{'id': '318', 'type': 'attribute', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'Python'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'Value'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '326', 'type': 'return_statement', 'children': ['327']},{'id': '327', 'type': 'tuple', 'children': ['328', '332']},{'id': '328', 'type': 'list', 'children': ['329'], 'value': '[target[0]]'},{'id': '329', 'type': 'subscript', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '331', 'type': 'integer', 'children': [], 'value': '0'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'source'}
def solutionEmitter(target, source, env): if source[0] == target[0]: source = [] (base, suff) = SCons.Util.splitext(str(target[0])) suff = env.subst('$MSVSSOLUTIONSUFFIX') target[0] = base + suff if not source: source = 'sln_inputs:' if 'name' in env: if SCons.Util.is_String(env['name']): source = source + ' "%s"' % env['name'] else: raise SCons.Errors.InternalError("name must be a string") if 'variant' in env: if SCons.Util.is_String(env['variant']): source = source + ' "%s"' % env['variant'] elif SCons.Util.is_List(env['variant']): for variant in env['variant']: if SCons.Util.is_String(variant): source = source + ' "%s"' % variant else: raise SCons.Errors.InternalError("name must be a string or a list of strings") else: raise SCons.Errors.InternalError("variant must be a string or a list of strings") else: raise SCons.Errors.InternalError("variant must be specified") if 'slnguid' in env: if SCons.Util.is_String(env['slnguid']): source = source + ' "%s"' % env['slnguid'] else: raise SCons.Errors.InternalError("slnguid must be a string") if 'projects' in env: if SCons.Util.is_String(env['projects']): source = source + ' "%s"' % env['projects'] elif SCons.Util.is_List(env['projects']): for t in env['projects']: if SCons.Util.is_String(t): source = source + ' "%s"' % t source = source + ' "%s"' % str(target[0]) source = [SCons.Node.Python.Value(source)] return ([target[0]], source)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_message'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '20', '24', '153']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'to_check'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'deque'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'list', 'children': ['17'], 'value': '[self._waiters]'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_waiters'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ignored'},{'id': '23', 'type': 'True', 'children': []},{'id': '24', 'type': 'while_statement', 'children': ['25', '31']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '30'], 'value': '>'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'to_check'},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'block', 'children': ['32', '40', '52', '107']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'to_check'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'popleft'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'waiters'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '47', 'type': 'argument_list', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'OperationManager'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_LEAF'},{'id': '51', 'type': 'list', 'children': [], 'value': '[]'},{'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'waiter'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'waiters'},{'id': '55', 'type': 'block', 'children': ['56', '103']},{'id': '56', 'type': 'if_statement', 'children': ['57', '64', '72']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'waiter'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'Future'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'waiter'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'set_result'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '72', 'type': 'else_clause', 'children': ['73']},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'try_statement', 'children': ['75', '87']},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'await', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': '_wait_or_launch'},{'id': '80', 'type': 'argument_list', 'children': ['81', '84', '85', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_loop'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'waiter'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '87', 'type': 'except_clause', 'children': ['88']},{'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': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98', '99', '100']},{'id': '97', 'type': 'string', 'children': [], 'value': '"Error calling every_match callback, callback=%s, message=%s"'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'waiter'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '102', 'type': 'True', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ignored'},{'id': '106', 'type': 'False', 'children': []},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '110', 'type': 'block', 'children': ['111', '119', '127', '133', '139']},{'id': '111', 'type': 'if_statement', 'children': ['112', '117']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'is'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'OperationManager'},{'id': '116', 'type': 'identifier', 'children': [], 'value': '_LEAF'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'continue_statement', 'children': []},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'message_val'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': '_get_key'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '127', 'type': 'if_statement', 'children': ['128', '131']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'is'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'message_val'},{'id': '130', 'type': 'identifier', 'children': [], 'value': '_MISSING'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'continue_statement', 'children': []},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'next_level'},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '139', 'type': 'if_statement', 'children': ['140', '143']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'in'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'message_val'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'next_level'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'to_check'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'next_level'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'message_val'},{'id': '153', 'type': 'return_statement', 'children': ['154']},{'id': '154', 'type': 'not_operator', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'ignored'}
async def process_message(self, message, wait=True): to_check = deque([self._waiters]) ignored = True while len(to_check) > 0: context = to_check.popleft() waiters = context.get(OperationManager._LEAF, []) for waiter in waiters: if isinstance(waiter, asyncio.Future): waiter.set_result(message) else: try: await _wait_or_launch(self._loop, waiter, message, wait) except: self._logger.warning("Error calling every_match callback, callback=%s, message=%s", waiter, message, exc_info=True) ignored = False for key in context: if key is OperationManager._LEAF: continue message_val = _get_key(message, key) if message_val is _MISSING: continue next_level = context[key] if message_val in next_level: to_check.append(next_level[message_val]) return not ignored
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compile'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '6', 'type': 'block', 'children': ['7', '19', '31', '43', '56', '60', '76', '107', '122', '193']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'is_international'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '19', 'type': 'function_definition', 'children': ['20', '21', '23']},{'id': '20', 'type': 'function_name', 'children': [], 'value': 'get_country_code'},{'id': '21', 'type': 'parameters', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'tag'},{'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': 'tag'},{'id': '27', 'type': 'slice', 'children': ['28', '30']},{'id': '28', 'type': 'unary_operator', 'children': ['29'], 'value': '-'},{'id': '29', 'type': 'integer', 'children': [], 'value': '2'},{'id': '30', 'type': 'colon', 'children': []},{'id': '31', 'type': 'function_definition', 'children': ['32', '33', '35']},{'id': '32', 'type': 'function_name', 'children': [], 'value': 'strip_country_code'},{'id': '33', 'type': 'parameters', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '39', 'type': 'slice', 'children': ['40', '41']},{'id': '40', 'type': 'colon', 'children': []},{'id': '41', 'type': 'unary_operator', 'children': ['42'], 'value': '-'},{'id': '42', 'type': 'integer', 'children': [], 'value': '2'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'replacements'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '48', 'type': 'argument_list', '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': 'tagset'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '59', 'type': 'string', 'children': [], 'value': '""'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'domestic'},{'id': '63', 'type': 'list_comprehension', 'children': ['64', '65', '68']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'replacements'},{'id': '68', 'type': 'if_clause', 'children': ['69']},{'id': '69', 'type': 'not_operator', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'is_international'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'for_statement', 'children': ['77', '80', '81']},{'id': '77', 'type': 'pattern_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'replacement'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'domestic'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'try_statement', 'children': ['83', '94']},{'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': 'str'},{'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '+'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '%'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'replacement'},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '94', 'type': 'except_clause', 'children': ['95', '99']},{'id': '95', 'type': 'as_pattern', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '97', 'type': 'as_pattern_target', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'if_statement', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'mandatory'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'raise_statement', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'international'},{'id': '110', 'type': 'list_comprehension', 'children': ['111', '112', '115']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'replacements'},{'id': '115', 'type': 'if_clause', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'is_international'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '121', 'type': 'integer', 'children': [], 'value': '0'},{'id': '122', 'type': 'for_statement', 'children': ['123', '126', '127']},{'id': '123', 'type': 'pattern_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'replacement'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'international'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'try_statement', 'children': ['129', '180']},{'id': '129', 'type': 'block', 'children': ['130', '151', '168']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '133', 'type': 'list_comprehension', 'children': ['134', '135', '142']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '135', 'type': 'for_in_clause', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'if_clause', 'children': ['143']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '150'], 'value': '=='},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'strip_country_code'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '149', 'type': 'integer', 'children': [], 'value': '0'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'int_values_for_key'},{'id': '154', 'type': 'list_comprehension', 'children': ['155', '165']},{'id': '155', 'type': 'tuple', 'children': ['156', '162']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'get_country_code'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '161', 'type': 'integer', 'children': [], 'value': '0'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '164', 'type': 'integer', 'children': [], 'value': '1'},{'id': '165', 'type': 'for_in_clause', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '168', 'type': 'for_statement', 'children': ['169', '170', '171']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'int_values_for_key'},{'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': 'str'},{'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '+'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '%'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'replacement'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '180', 'type': 'except_clause', 'children': ['181', '185']},{'id': '181', 'type': 'as_pattern', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '183', 'type': 'as_pattern_target', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'if_statement', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'mandatory'},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'raise_statement', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '193', 'type': 'return_statement', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'str'}
def compile(self, values): def is_international(tag): return tag.endswith('_') def get_country_code(tag): return tag[-2:] def strip_country_code(tag): return tag[:-2] replacements = list(self.tagset.items()) str = "" domestic = [t for t in replacements if not is_international(t[0])] for key, replacement in domestic: try: str = str + replacement % values[key] except KeyError as e: if self.mandatory: raise e international = [t for t in replacements if is_international(t[0])] for key, replacement in international: try: x = [t for t in values.items() if strip_country_code(t[0]) == key] int_values_for_key = [(get_country_code(t[0]),t[1]) for t in x] for v in int_values_for_key: str = str + replacement % v except KeyError as e: if self.mandatory: raise e return str
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'FromReadings'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '12', '15', '20', '23', '26']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'readings'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'root_key'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'AuthProvider'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'NoKey'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'signer'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'report_id'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'IOTileReading'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'InvalidReadingID'},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0xFFFF'},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sent_timestamp'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'block', 'children': ['30', '36', '42', '55', '61', '67', '85', '107', '127', '134', '140', '173', '184', '195', '261', '296', '315', '322', '328']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'lowest_id'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'IOTileReading'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'InvalidReadingID'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'highest_id'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'IOTileReading'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'InvalidReadingID'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'report_len'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '54'], 'value': '+'},{'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '+'},{'id': '47', 'type': 'integer', 'children': [], 'value': '20'},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '*'},{'id': '49', 'type': 'integer', 'children': [], 'value': '16'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'readings'},{'id': '54', 'type': 'integer', 'children': [], 'value': '24'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len_low'},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '&'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'report_len'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0xFF'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'len_high'},{'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '>>'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'report_len'},{'id': '66', 'type': 'integer', 'children': [], 'value': '8'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'unique_readings'},{'id': '70', 'type': 'list_comprehension', 'children': ['71', '74', '77']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'reading_id'},{'id': '74', 'type': 'for_in_clause', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'readings'},{'id': '77', 'type': 'if_clause', 'children': ['78']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': '!='},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'reading_id'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'IOTileReading'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'InvalidReadingID'},{'id': '85', 'type': 'if_statement', 'children': ['86', '92']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '91'], 'value': '>'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'unique_readings'},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'block', 'children': ['93', '100']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'lowest_id'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'unique_readings'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'highest_id'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'unique_readings'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'struct'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116', '119', '120', '121', '122', '123', '124', '125', '126']},{'id': '115', 'type': 'string', 'children': [], 'value': '"<BBHLLLBBH"'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'ReportType'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'len_low'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'len_high'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'report_id'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sent_timestamp'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'root_key'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'packed_readings'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '139', 'type': 'argument_list', 'children': []},{'id': '140', 'type': 'for_statement', 'children': ['141', '142', '143']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'readings'},{'id': '143', 'type': 'block', 'children': ['144', '166']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'packed_reading'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'struct'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153', '156', '157', '160', '163']},{'id': '152', 'type': 'string', 'children': [], 'value': '"<HHLLL"'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '156', 'type': 'integer', 'children': [], 'value': '0'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'reading_id'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'raw_time'},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'augmented_assignment', 'children': ['168', '169'], 'value': '+='},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'packed_readings'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'packed_reading'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'footer_stats'},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'struct'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182', '183']},{'id': '181', 'type': 'string', 'children': [], 'value': '"<LL"'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'lowest_id'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'highest_id'},{'id': '184', 'type': 'if_statement', 'children': ['185', '188']},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': 'is'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'signer'},{'id': '187', 'type': 'None', 'children': []},{'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': 'signer'},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'ChainedAuthProvider'},{'id': '194', 'type': 'argument_list', 'children': []},{'id': '195', 'type': 'if_statement', 'children': ['196', '201', '251']},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': '!='},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'root_key'},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'signer'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'NoKey'},{'id': '201', 'type': 'block', 'children': ['202', '206', '241']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'enc_data'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'packed_readings'},{'id': '206', 'type': 'try_statement', 'children': ['207', '225']},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'signer'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'encrypt_report'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217', '218', '219', '222']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'root_key'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'enc_data'},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'report_id'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'report_id'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'sent_timestamp'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'sent_timestamp'},{'id': '225', 'type': 'except_clause', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'raise_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'ExternalError'},{'id': '231', 'type': 'argument_list', 'children': ['232', '235', '238']},{'id': '232', 'type': 'concatenated_string', 'children': ['233', '234']},{'id': '233', 'type': 'string', 'children': [], 'value': '"Could not encrypt report because no AuthProvider supported "'},{'id': '234', 'type': 'string', 'children': [], 'value': '"the requested encryption method for the requested device"'},{'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'device_id'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'root_key'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'root_key'},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'signed_data'},{'id': '244', 'type': 'binary_operator', 'children': ['245', '250'], 'value': '+'},{'id': '245', 'type': 'binary_operator', 'children': ['246', '247'], 'value': '+'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '247', 'type': 'subscript', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '249', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'footer_stats'},{'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': 'signed_data'},{'id': '256', 'type': 'binary_operator', 'children': ['257', '260'], 'value': '+'},{'id': '257', 'type': 'binary_operator', 'children': ['258', '259'], 'value': '+'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'packed_readings'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'footer_stats'},{'id': '261', 'type': 'try_statement', 'children': ['262', '280']},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'signer'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'sign_report'},{'id': '270', 'type': 'argument_list', 'children': ['271', '272', '273', '274', '277']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'root_key'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'signed_data'},{'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'report_id'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'report_id'},{'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'sent_timestamp'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'sent_timestamp'},{'id': '280', 'type': 'except_clause', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '282', 'type': 'block', 'children': ['283']},{'id': '283', 'type': 'raise_statement', 'children': ['284']},{'id': '284', 'type': 'call', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'ExternalError'},{'id': '286', 'type': 'argument_list', 'children': ['287', '290', '293']},{'id': '287', 'type': 'concatenated_string', 'children': ['288', '289']},{'id': '288', 'type': 'string', 'children': [], 'value': '"Could not sign report because no AuthProvider supported the requested "'},{'id': '289', 'type': 'string', 'children': [], 'value': '"signature method for the requested device"'},{'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'device_id'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'root_key'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'root_key'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'footer'},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'struct'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '303', 'type': 'argument_list', 'children': ['304', '305']},{'id': '304', 'type': 'string', 'children': [], 'value': '"16s"'},{'id': '305', 'type': 'call', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'subscript', 'children': ['309', '312']},{'id': '309', 'type': 'subscript', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '311', 'type': 'string', 'children': [], 'value': "'signature'"},{'id': '312', 'type': 'slice', 'children': ['313', '314']},{'id': '313', 'type': 'colon', 'children': []},{'id': '314', 'type': 'integer', 'children': [], 'value': '16'},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'assignment', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'footer'},{'id': '318', 'type': 'call', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'footer'},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'assignment', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '325', 'type': 'binary_operator', 'children': ['326', '327'], 'value': '+'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'signed_data'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'footer'},{'id': '328', 'type': 'return_statement', 'children': ['329']},{'id': '329', 'type': 'call', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'SignedListReport'},{'id': '331', 'type': 'argument_list', 'children': ['332']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'data'}
def FromReadings(cls, uuid, readings, root_key=AuthProvider.NoKey, signer=None, report_id=IOTileReading.InvalidReadingID, selector=0xFFFF, streamer=0, sent_timestamp=0): lowest_id = IOTileReading.InvalidReadingID highest_id = IOTileReading.InvalidReadingID report_len = 20 + 16*len(readings) + 24 len_low = report_len & 0xFF len_high = report_len >> 8 unique_readings = [x.reading_id for x in readings if x.reading_id != IOTileReading.InvalidReadingID] if len(unique_readings) > 0: lowest_id = min(unique_readings) highest_id = max(unique_readings) header = struct.pack("<BBHLLLBBH", cls.ReportType, len_low, len_high, uuid, report_id, sent_timestamp, root_key, streamer, selector) header = bytearray(header) packed_readings = bytearray() for reading in readings: packed_reading = struct.pack("<HHLLL", reading.stream, 0, reading.reading_id, reading.raw_time, reading.value) packed_readings += bytearray(packed_reading) footer_stats = struct.pack("<LL", lowest_id, highest_id) if signer is None: signer = ChainedAuthProvider() if root_key != signer.NoKey: enc_data = packed_readings try: result = signer.encrypt_report(uuid, root_key, enc_data, report_id=report_id, sent_timestamp=sent_timestamp) except NotFoundError: raise ExternalError("Could not encrypt report because no AuthProvider supported " "the requested encryption method for the requested device", device_id=uuid, root_key=root_key) signed_data = header + result['data'] + footer_stats else: signed_data = header + packed_readings + footer_stats try: signature = signer.sign_report(uuid, root_key, signed_data, report_id=report_id, sent_timestamp=sent_timestamp) except NotFoundError: raise ExternalError("Could not sign report because no AuthProvider supported the requested " "signature method for the requested device", device_id=uuid, root_key=root_key) footer = struct.pack("16s", bytes(signature['signature'][:16])) footer = bytearray(footer) data = signed_data + footer return SignedListReport(data)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'format_snippet'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '5', 'type': 'block', 'children': ['6', '10', '17', '24', '31', '51', '105', '145', '152', '159', '170', '181', '220', '227', '234', '304', '311', '318']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': '"disable"'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': '"clear"'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': '"reset"'},{'id': '31', 'type': 'for_statement', 'children': ['32', '33', '38']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'dump_nodes'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': '\'add_node "{}"\''},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '51', 'type': 'for_statement', 'children': ['52', '53', '56']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'streamers'},{'id': '56', 'type': 'block', 'children': ['57', '80', '98']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': '"add_streamer \'{}\' \'{}\' {} {} {}"'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '64', 'type': 'argument_list', 'children': ['65', '68', '71', '74', '77']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'automatic'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'report_type'},{'id': '80', 'type': 'if_statement', 'children': ['81', '86']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': 'is'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'with_other'},{'id': '85', 'type': 'None', 'children': []},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'augmented_assignment', 'children': ['89', '90'], 'value': '+='},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'string', 'children': [], 'value': "' --withother {}'"},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'with_other'},{'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': 'output'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '105', 'type': 'for_statement', 'children': ['106', '109', '131']},{'id': '106', 'type': 'pattern_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '111', 'type': 'argument_list', 'children': ['112', '119']},{'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': 'sensor_graph'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'constant_database'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '121', 'type': 'lambda', 'children': ['122', '124']},{'id': '122', 'type': 'lambda_parameters', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '124', 'type': 'call', 'children': ['125', '130']},{'id': '125', 'type': 'attribute', 'children': ['126', '129']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '128', 'type': 'integer', 'children': [], 'value': '0'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '130', 'type': 'argument_list', 'children': []},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': '"set_constant \'{}\' {}"'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'string', 'children': [], 'value': '"persist"'},{'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': 'output'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'string', 'children': [], 'value': '"back"'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'app_tag'},{'id': '162', 'type': 'call', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'metadata_database'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'string', 'children': [], 'value': "'app_tag'"},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'app_version'},{'id': '173', 'type': 'call', 'children': ['174', '179']},{'id': '174', 'type': 'attribute', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'metadata_database'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'string', 'children': [], 'value': "'app_version'"},{'id': '181', 'type': 'if_statement', 'children': ['182', '185']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'is'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'app_tag'},{'id': '184', 'type': 'None', 'children': []},{'id': '185', 'type': 'block', 'children': ['186', '195', '202', '213']},{'id': '186', 'type': 'if_statement', 'children': ['187', '190']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'is'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'app_version'},{'id': '189', 'type': 'None', 'children': []},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'app_version'},{'id': '194', 'type': 'string', 'children': [], 'value': '"0.0"'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'string', 'children': [], 'value': '"test_interface"'},{'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': 'binary_operator', 'children': ['209', '210'], 'value': '%'},{'id': '209', 'type': 'string', 'children': [], 'value': '"set_version app %d --version \'%s\'"'},{'id': '210', 'type': 'tuple', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'app_tag'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'app_version'},{'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': 'output'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'string', 'children': [], 'value': '"back"'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'string', 'children': [], 'value': '"config_database"'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'string', 'children': [], 'value': '"clear_variables"'},{'id': '234', 'type': 'for_statement', 'children': ['235', '238', '245']},{'id': '235', 'type': 'pattern_list', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'slot'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'conf_vars'},{'id': '238', 'type': 'call', 'children': ['239', '244']},{'id': '239', 'type': 'attribute', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'config_database'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '244', 'type': 'argument_list', 'children': []},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'for_statement', 'children': ['247', '250', '255']},{'id': '247', 'type': 'pattern_list', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'conf_var'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'conf_def'},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'conf_vars'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '254', 'type': 'argument_list', 'children': []},{'id': '255', 'type': 'block', 'children': ['256', '262', '289']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '261']},{'id': '258', 'type': 'pattern_list', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'conf_type'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'conf_val'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'conf_def'},{'id': '262', 'type': 'if_statement', 'children': ['263', '266', '276']},{'id': '263', 'type': 'comparison_operator', 'children': ['264', '265'], 'value': '=='},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'conf_type'},{'id': '265', 'type': 'string', 'children': [], 'value': "'binary'"},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'conf_val'},{'id': '270', 'type': 'binary_operator', 'children': ['271', '272'], 'value': '+'},{'id': '271', 'type': 'string', 'children': [], 'value': "'hex:'"},{'id': '272', 'type': 'call', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'hexlify'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'conf_val'},{'id': '276', 'type': 'elif_clause', 'children': ['277', '282']},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '279', 'type': 'argument_list', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'conf_val'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '282', 'type': 'block', 'children': ['283']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'conf_val'},{'id': '286', 'type': 'binary_operator', 'children': ['287', '288'], 'value': '%'},{'id': '287', 'type': 'string', 'children': [], 'value': '\'"%s"\''},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'conf_val'},{'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': 'output'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'string', 'children': [], 'value': '"set_variable \'{}\' {} {} {}"'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '299', 'type': 'argument_list', 'children': ['300', '301', '302', '303']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'slot'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'conf_var'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'conf_type'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'conf_val'},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'string', 'children': [], 'value': '"back"'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'string', 'children': [], 'value': '"reset"'},{'id': '318', 'type': 'return_statement', 'children': ['319']},{'id': '319', 'type': 'binary_operator', 'children': ['320', '326'], 'value': '+'},{'id': '320', 'type': 'call', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '326', 'type': 'string', 'children': [], 'value': "'\\n'"}
def format_snippet(sensor_graph): output = [] output.append("disable") output.append("clear") output.append("reset") for node in sensor_graph.dump_nodes(): output.append('add_node "{}"'.format(node)) for streamer in sensor_graph.streamers: line = "add_streamer '{}' '{}' {} {} {}".format(streamer.selector, streamer.dest, streamer.automatic, streamer.format, streamer.report_type) if streamer.with_other is not None: line += ' --withother {}'.format(streamer.with_other) output.append(line) for stream, value in sorted(sensor_graph.constant_database.items(), key=lambda x: x[0].encode()): output.append("set_constant '{}' {}".format(stream, value)) output.append("persist") output.append("back") app_tag = sensor_graph.metadata_database.get('app_tag') app_version = sensor_graph.metadata_database.get('app_version') if app_tag is not None: if app_version is None: app_version = "0.0" output.append("test_interface") output.append("set_version app %d --version '%s'" % (app_tag, app_version)) output.append("back") output.append("config_database") output.append("clear_variables") for slot, conf_vars in sensor_graph.config_database.items(): for conf_var, conf_def in conf_vars.items(): conf_type, conf_val = conf_def if conf_type == 'binary': conf_val = 'hex:' + hexlify(conf_val) elif isinstance(conf_val, str): conf_val = '"%s"' % conf_val output.append("set_variable '{}' {} {} {}".format(slot, conf_var, conf_type, conf_val)) output.append("back") output.append("reset") return "\n".join(output) + '\n'
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_process_scan_event'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '6', 'type': 'block', 'children': ['7', '13', '22', '28', '44', '70', '98', '104']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '16', 'type': 'binary_operator', 'children': ['17', '21'], 'value': '-'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '21', 'type': 'integer', 'children': [], 'value': '10'},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': '<'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '37']},{'id': '30', 'type': 'pattern_list', 'children': ['31', '32', '33', '34', '35', '36']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'rssi'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'packet_type'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sender'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_addr_type'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_bond'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '39', 'type': 'argument_list', 'children': ['40', '43']},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '%'},{'id': '41', 'type': 'string', 'children': [], 'value': '"<bB6sBB%ds"'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'string_address'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': "':'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'list_comprehension', 'children': ['53', '58']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '57', 'type': 'string', 'children': [], 'value': '"02X"'},{'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sender'},{'id': '65', 'type': 'slice', 'children': ['66', '67', '68']},{'id': '66', 'type': 'colon', 'children': []},{'id': '67', 'type': 'colon', 'children': []},{'id': '68', 'type': 'unary_operator', 'children': ['69'], 'value': '-'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'if_statement', 'children': ['71', '77', '89']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '76'], 'value': '>'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '76', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'data'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '86', 'type': 'slice', 'children': ['87', '88']},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'colon', 'children': []},{'id': '89', 'type': 'else_clause', 'children': ['90']},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'list', 'children': [], 'value': '[]'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'augmented_assignment', 'children': ['100', '103'], 'value': '+='},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': '_scan_event_count'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1'},{'id': '104', 'type': 'if_statement', 'children': ['105', '111', '198']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'in'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'packet_type'},{'id': '107', 'type': 'tuple', 'children': ['108', '109', '110']},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'integer', 'children': [], 'value': '2'},{'id': '110', 'type': 'integer', 'children': [], 'value': '6'},{'id': '111', 'type': 'block', 'children': ['112', '121']},{'id': '112', 'type': 'if_statement', 'children': ['113', '119']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '118'], 'value': '!='},{'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': 'data'},{'id': '118', 'type': 'integer', 'children': [], 'value': '31'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'return_statement', 'children': []},{'id': '121', 'type': 'if_statement', 'children': ['122', '139', '155', '195']},{'id': '122', 'type': 'boolean_operator', 'children': ['123', '134'], 'value': 'and'},{'id': '123', 'type': 'boolean_operator', 'children': ['124', '129'], 'value': 'and'},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '128'], 'value': '=='},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '127', 'type': 'integer', 'children': [], 'value': '22'},{'id': '128', 'type': 'integer', 'children': [], 'value': '0xFF'},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': '=='},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '132', 'type': 'integer', 'children': [], 'value': '23'},{'id': '133', 'type': 'integer', 'children': [], 'value': '0xC0'},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '138'], 'value': '=='},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '137', 'type': 'integer', 'children': [], 'value': '24'},{'id': '138', 'type': 'integer', 'children': [], 'value': '0x3'},{'id': '139', 'type': 'block', 'children': ['140', '146']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'augmented_assignment', 'children': ['142', '145'], 'value': '+='},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': '_v1_scan_count'},{'id': '145', 'type': 'integer', 'children': [], 'value': '1'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': '_parse_v1_advertisement'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153', '154']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'rssi'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'string_address'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '155', 'type': 'elif_clause', 'children': ['156', '179']},{'id': '156', 'type': 'boolean_operator', 'children': ['157', '174'], 'value': 'and'},{'id': '157', 'type': 'boolean_operator', 'children': ['158', '169'], 'value': 'and'},{'id': '158', 'type': 'boolean_operator', 'children': ['159', '164'], 'value': 'and'},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '163'], 'value': '=='},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '162', 'type': 'integer', 'children': [], 'value': '3'},{'id': '163', 'type': 'integer', 'children': [], 'value': '27'},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '168'], 'value': '=='},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '167', 'type': 'integer', 'children': [], 'value': '4'},{'id': '168', 'type': 'integer', 'children': [], 'value': '0x16'},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '173'], 'value': '=='},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '172', 'type': 'integer', 'children': [], 'value': '5'},{'id': '173', 'type': 'integer', 'children': [], 'value': '0xdd'},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '178'], 'value': '=='},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '177', 'type': 'integer', 'children': [], 'value': '6'},{'id': '178', 'type': 'integer', 'children': [], 'value': '0xfd'},{'id': '179', 'type': 'block', 'children': ['180', '186']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'augmented_assignment', 'children': ['182', '185'], 'value': '+='},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '184', 'type': 'identifier', 'children': [], 'value': '_v2_scan_count'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '190', 'type': 'identifier', 'children': [], 'value': '_parse_v2_advertisement'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193', '194']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'rssi'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'string_address'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '195', 'type': 'else_clause', 'children': ['196']},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'pass_statement', 'children': []},{'id': '198', 'type': 'elif_clause', 'children': ['199', '202']},{'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': '=='},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'packet_type'},{'id': '201', 'type': 'integer', 'children': [], 'value': '4'},{'id': '202', 'type': 'block', 'children': ['203', '209']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'augmented_assignment', 'children': ['205', '208'], 'value': '+='},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': '_v1_scan_response_count'},{'id': '208', 'type': 'integer', 'children': [], 'value': '1'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': '_parse_v1_scan_response'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'string_address'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'data'}
def _process_scan_event(self, response): payload = response.payload length = len(payload) - 10 if length < 0: return rssi, packet_type, sender, _addr_type, _bond, data = unpack("<bB6sBB%ds" % length, payload) string_address = ':'.join([format(x, "02X") for x in bytearray(sender[::-1])]) if len(data) > 0: data = bytearray(data[1:]) else: data = bytearray([]) self._scan_event_count += 1 if packet_type in (0, 2, 6): if len(data) != 31: return if data[22] == 0xFF and data[23] == 0xC0 and data[24] == 0x3: self._v1_scan_count += 1 self._parse_v1_advertisement(rssi, string_address, data) elif data[3] == 27 and data[4] == 0x16 and data[5] == 0xdd and data[6] == 0xfd: self._v2_scan_count += 1 self._parse_v2_advertisement(rssi, string_address, data) else: pass elif packet_type == 4: self._v1_scan_response_count += 1 self._parse_v1_scan_response(string_address, data)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_ver_range'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ver_range'},{'id': '7', 'type': 'block', 'children': ['8', '16', '27', '51', '75', '133']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '15']},{'id': '10', 'type': 'pattern_list', 'children': ['11', '12', '13', '14']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'lower_inc'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'upper_inc'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ver_range'},{'id': '16', 'type': 'if_statement', 'children': ['17', '24']},{'id': '17', 'type': 'boolean_operator', 'children': ['18', '21'], 'value': 'and'},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'True', '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': 'lower'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'if_statement', 'children': ['33', '38', '41']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '35'], 'value': 'and'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'lower_inc'},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '<'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'False', 'children': []},{'id': '41', 'type': 'elif_clause', 'children': ['42', '48']},{'id': '42', 'type': 'boolean_operator', 'children': ['43', '45'], 'value': 'and'},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'lower_inc'},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<='},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'False', 'children': []},{'id': '51', 'type': 'if_statement', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'if_statement', 'children': ['57', '62', '65']},{'id': '57', 'type': 'boolean_operator', 'children': ['58', '59'], 'value': 'and'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'upper_inc'},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': '>'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'False', 'children': []},{'id': '65', 'type': 'elif_clause', 'children': ['66', '72']},{'id': '66', 'type': 'boolean_operator', 'children': ['67', '69'], 'value': 'and'},{'id': '67', 'type': 'not_operator', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'upper_inc'},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '>='},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'False', 'children': []},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'is_prerelease'},{'id': '79', 'type': 'block', 'children': ['80', '103']},{'id': '80', 'type': 'if_statement', 'children': ['81', '100']},{'id': '81', 'type': 'boolean_operator', 'children': ['82', '91'], 'value': 'and'},{'id': '82', 'type': '()', 'children': ['83']},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '87'], 'value': 'or'},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'is'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '86', 'type': 'None', 'children': []},{'id': '87', 'type': 'not_operator', 'children': ['88']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'is_prerelease'},{'id': '91', 'type': '()', 'children': ['92']},{'id': '92', 'type': 'boolean_operator', 'children': ['93', '96'], 'value': 'or'},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'is'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '95', 'type': 'None', 'children': []},{'id': '96', 'type': 'not_operator', 'children': ['97']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'is_prerelease'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'return_statement', 'children': ['102']},{'id': '102', 'type': 'False', 'children': []},{'id': '103', 'type': 'if_statement', 'children': ['104', '130']},{'id': '104', 'type': 'boolean_operator', 'children': ['105', '117', '118'], 'value': 'and'},{'id': '105', 'type': '()', 'children': ['106']},{'id': '106', 'type': 'boolean_operator', 'children': ['107', '110'], 'value': 'and'},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'is'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '109', 'type': 'None', 'children': []},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '114'], 'value': '!='},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'release_tuple'},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'release_tuple'},{'id': '117', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '118', 'type': '()', 'children': ['119']},{'id': '119', 'type': 'boolean_operator', 'children': ['120', '123'], 'value': 'and'},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'is'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '122', 'type': 'None', 'children': []},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '127'], 'value': '!='},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'release_tuple'},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'release_tuple'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'return_statement', 'children': ['132']},{'id': '132', 'type': 'False', 'children': []},{'id': '133', 'type': 'return_statement', 'children': ['134']},{'id': '134', 'type': 'True', 'children': []}
def _check_ver_range(self, version, ver_range): lower, upper, lower_inc, upper_inc = ver_range if lower is None and upper is None: return True if lower is not None: if lower_inc and version < lower: return False elif not lower_inc and version <= lower: return False if upper is not None: if upper_inc and version > upper: return False elif not upper_inc and version >= upper: return False if version.is_prerelease: if (lower is None or not lower.is_prerelease) and (upper is None or not upper.is_prerelease): return False if (lower is not None and version.release_tuple != lower.release_tuple) and \ (upper is not None and version.release_tuple != upper.release_tuple): return False return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_LaTeX'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'flist'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '7', 'type': 'block', 'children': ['8', '17', '25', '49', '76', '91', '246']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'savedpath'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'modify_env_var'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '15', 'type': 'string', 'children': [], 'value': "'TEXINPUTS'"},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '20', 'type': 'subscript', 'children': ['21', '24']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '23', 'type': 'string', 'children': [], 'value': "'ENV'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'TEXINPUTS'"},{'id': '25', 'type': 'if_statement', 'children': ['26', '34', '36']},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'is_List'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'pass_statement', 'children': []},{'id': '36', 'type': 'else_clause', 'children': ['37']},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'pathsep'},{'id': '49', 'type': 'if_statement', 'children': ['50', '53', '66']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'savedpath'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_null'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'try_statement', 'children': ['55', '62']},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'delete_statement', 'children': ['57']},{'id': '57', 'type': 'subscript', 'children': ['58', '61']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '60', 'type': 'string', 'children': [], 'value': "'ENV'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'TEXINPUTS'"},{'id': '62', 'type': 'except_clause', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'pass_statement', 'children': []},{'id': '66', 'type': 'else_clause', 'children': ['67']},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '75']},{'id': '70', 'type': 'subscript', 'children': ['71', '74']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '73', 'type': 'string', 'children': [], 'value': "'ENV'"},{'id': '74', 'type': 'string', 'children': [], 'value': "'TEXINPUTS'"},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'savedpath'},{'id': '76', 'type': 'if_statement', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'Verbose'},{'id': '78', 'type': 'block', 'children': ['79', '85']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': '"is_LaTeX search path "'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': '"files to search :"'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'flist'},{'id': '91', 'type': 'for_statement', 'children': ['92', '93', '94']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'flist'},{'id': '94', 'type': 'block', 'children': ['95', '107', '115', '138', '151', '155', '167', '181', '234']},{'id': '95', 'type': 'if_statement', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'Verbose'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': '" checking for Latex source "'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'get_text_contents'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'if_statement', 'children': ['116', '122']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'LaTeX_re'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '122', 'type': 'block', 'children': ['123', '136']},{'id': '123', 'type': 'if_statement', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'Verbose'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '%'},{'id': '131', 'type': 'string', 'children': [], 'value': '"file %s is a LaTeX file"'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '136', 'type': 'return_statement', 'children': ['137']},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'if_statement', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'Verbose'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '%'},{'id': '146', 'type': 'string', 'children': [], 'value': '"file %s is not a LaTeX file"'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'inc_files'},{'id': '154', 'type': 'list', 'children': [], 'value': '[ ]'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'inc_files'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'include_re'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '167', 'type': 'if_statement', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'Verbose'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '173', 'type': 'argument_list', 'children': ['174', '180']},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '%'},{'id': '175', 'type': 'string', 'children': [], 'value': '"files included by \'%s\': "'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'inc_files'},{'id': '181', 'type': 'for_statement', 'children': ['182', '183', '184']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'inc_files'},{'id': '184', 'type': 'block', 'children': ['185', '201', '206', '215', '229']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'srcNode'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'FindFile'},{'id': '190', 'type': 'argument_list', 'children': ['191', '192', '196', '197', '198']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '192', 'type': 'list', 'children': ['193', '194', '195'], 'value': "['.tex','.ltx','.latex']"},{'id': '193', 'type': 'string', 'children': [], 'value': "'.tex'"},{'id': '194', 'type': 'string', 'children': [], 'value': "'.ltx'"},{'id': '195', 'type': 'string', 'children': [], 'value': "'.latex'"},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'requireExt'},{'id': '200', 'type': 'False', 'children': []},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'fileList'},{'id': '204', 'type': 'list', 'children': ['205'], 'value': '[srcNode,]'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'srcNode'},{'id': '206', 'type': 'if_statement', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'Verbose'},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'string', 'children': [], 'value': '"FindFile found "'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'srcNode'},{'id': '215', 'type': 'if_statement', 'children': ['216', '219']},{'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': 'is'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'srcNode'},{'id': '218', 'type': 'None', 'children': []},{'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': 'file_test'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'is_LaTeX'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227', '228']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'fileList'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '229', 'type': 'if_statement', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'file_test'},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'return_statement', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'file_test'},{'id': '234', 'type': 'if_statement', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'Verbose'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '240', 'type': 'argument_list', 'children': ['241', '242']},{'id': '241', 'type': 'string', 'children': [], 'value': '" done scanning "'},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '246', 'type': 'return_statement', 'children': ['247']},{'id': '247', 'type': 'integer', 'children': [], 'value': '0'}
def is_LaTeX(flist,env,abspath): savedpath = modify_env_var(env, 'TEXINPUTS', abspath) paths = env['ENV']['TEXINPUTS'] if SCons.Util.is_List(paths): pass else: paths = paths.split(os.pathsep) if savedpath is _null: try: del env['ENV']['TEXINPUTS'] except KeyError: pass else: env['ENV']['TEXINPUTS'] = savedpath if Verbose: print("is_LaTeX search path ",paths) print("files to search :",flist) for f in flist: if Verbose: print(" checking for Latex source ",str(f)) content = f.get_text_contents() if LaTeX_re.search(content): if Verbose: print("file %s is a LaTeX file" % str(f)) return 1 if Verbose: print("file %s is not a LaTeX file" % str(f)) inc_files = [ ] inc_files.extend( include_re.findall(content) ) if Verbose: print("files included by '%s': "%str(f),inc_files) for src in inc_files: srcNode = FindFile(src,['.tex','.ltx','.latex'],paths,env,requireExt=False) fileList = [srcNode,] if Verbose: print("FindFile found ",srcNode) if srcNode is not None: file_test = is_LaTeX(fileList, env, abspath) if file_test: return file_test if Verbose: print(" done scanning ",str(f)) return 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'processDefines'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'defs'},{'id': '5', 'type': 'block', 'children': ['6', '250']},{'id': '6', 'type': 'if_statement', 'children': ['7', '15', '179', '240']},{'id': '7', 'type': 'call', 'children': ['8', '13']},{'id': '8', 'type': 'attribute', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'is_List'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'defs'},{'id': '15', 'type': 'block', 'children': ['16', '20']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'defs'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'if_statement', 'children': ['25', '28', '30', '89', '143', '163']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'continue_statement', 'children': []},{'id': '30', 'type': 'elif_clause', 'children': ['31', '45']},{'id': '31', 'type': 'boolean_operator', 'children': ['32', '40'], 'value': 'or'},{'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': 'SCons'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'is_List'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'if_statement', 'children': ['47', '53', '75']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '52'], 'value': '>='},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '52', 'type': 'integer', 'children': [], 'value': '2'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'binary_operator', 'children': ['61', '69'], 'value': '+'},{'id': '61', 'type': 'binary_operator', 'children': ['62', '68'], 'value': '+'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'string', 'children': [], 'value': "'='"},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'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': 'l'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '88', 'type': 'integer', 'children': [], 'value': '0'},{'id': '89', 'type': 'elif_clause', 'children': ['90', '98']},{'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': 'SCons'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'is_Dict'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'for_statement', 'children': ['100', '103', '108']},{'id': '100', 'type': 'pattern_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'macro'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'if_statement', 'children': ['110', '113', '131']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'binary_operator', 'children': ['121', '127'], 'value': '+'},{'id': '121', 'type': 'binary_operator', 'children': ['122', '126'], 'value': '+'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'macro'},{'id': '126', 'type': 'string', 'children': [], 'value': "'='"},{'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': 'value'},{'id': '131', 'type': 'else_clause', 'children': ['132']},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'macro'},{'id': '143', 'type': 'elif_clause', 'children': ['144', '152']},{'id': '144', 'type': 'call', 'children': ['145', '150']},{'id': '145', 'type': 'attribute', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'is_String'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '163', 'type': 'else_clause', 'children': ['164']},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'raise_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '172']},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'Errors'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'UserError'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'binary_operator', 'children': ['174', '175'], 'value': '%'},{'id': '174', 'type': 'string', 'children': [], 'value': '"DEFINE %s is not a list, dict, string or None."'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '179', 'type': 'elif_clause', 'children': ['180', '188']},{'id': '180', 'type': 'call', 'children': ['181', '186']},{'id': '181', 'type': 'attribute', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'is_Dict'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'defs'},{'id': '188', 'type': 'block', 'children': ['189', '193']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '192', 'type': 'list', 'children': [], 'value': '[]'},{'id': '193', 'type': 'for_statement', 'children': ['194', '197', '205']},{'id': '194', 'type': 'pattern_list', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'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': 'defs'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '204', 'type': 'argument_list', 'children': []},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'if_statement', 'children': ['207', '210', '221']},{'id': '207', 'type': 'comparison_operator', 'children': ['208', '209'], 'value': 'is'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '209', 'type': 'None', 'children': []},{'id': '210', 'type': 'block', 'children': ['211']},{'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': 'l'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '221', 'type': 'else_clause', 'children': ['222']},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'binary_operator', 'children': ['230', '236'], 'value': '+'},{'id': '230', 'type': 'binary_operator', 'children': ['231', '235'], 'value': '+'},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '235', 'type': 'string', 'children': [], 'value': "'='"},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '240', 'type': 'else_clause', 'children': ['241']},{'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': 'l'},{'id': '245', 'type': 'list', 'children': ['246'], 'value': '[str(defs)]'},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'defs'},{'id': '250', 'type': 'return_statement', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'l'}
def processDefines(defs): if SCons.Util.is_List(defs): l = [] for d in defs: if d is None: continue elif SCons.Util.is_List(d) or isinstance(d, tuple): if len(d) >= 2: l.append(str(d[0]) + '=' + str(d[1])) else: l.append(str(d[0])) elif SCons.Util.is_Dict(d): for macro,value in d.items(): if value is not None: l.append(str(macro) + '=' + str(value)) else: l.append(str(macro)) elif SCons.Util.is_String(d): l.append(str(d)) else: raise SCons.Errors.UserError("DEFINE %s is not a list, dict, string or None."%repr(d)) elif SCons.Util.is_Dict(defs): l = [] for k,v in sorted(defs.items()): if v is None: l.append(str(k)) else: l.append(str(k) + '=' + str(v)) else: l = [str(defs)] return l
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'local_services'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '24']},{'id': '6', 'type': 'if_statement', 'children': ['7', '15']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '14']},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_loop'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'inside_loop'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_state_lock'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'acquire'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'try_statement', 'children': ['25', '53']},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '29', 'type': 'argument_list', 'children': ['30', '45']},{'id': '30', 'type': 'list_comprehension', 'children': ['31', '34']},{'id': '31', 'type': 'tuple', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '34', 'type': 'for_in_clause', 'children': ['35', '38']},{'id': '35', 'type': 'pattern_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '38', 'type': 'call', 'children': ['39', '44']},{'id': '39', 'type': 'attribute', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_name_map'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '47', 'type': 'lambda', 'children': ['48', '50']},{'id': '48', 'type': 'lambda_parameters', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'id': '53', 'type': 'finally_clause', 'children': ['54']},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'if_statement', 'children': ['56', '64']},{'id': '56', 'type': 'not_operator', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '63']},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_loop'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'inside_loop'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_state_lock'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '72', 'type': 'argument_list', 'children': []}
def local_services(self): if not self._loop.inside_loop(): self._state_lock.acquire() try: return sorted([(index, name) for index, name in self._name_map.items()], key=lambda element: element[0]) finally: if not self._loop.inside_loop(): self._state_lock.release()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '5', 'type': 'block', 'children': ['6', '14', '22', '30', '187', '219', '234', '274', '314', '322', '330', '343', '350', '357']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'CLVar'},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'CLVar'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Builder'},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'Builder'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'Builder'},{'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': 'env'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'SetDefault'},{'id': '35', 'type': 'argument_list', 'children': ['36', '42', '53', '64', '75', '86', '97', '100', '103', '109', '115', '121', '127', '130', '133', '136', '139', '142', '145', '148', '151', '154', '171', '175']},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'QTDIR'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_detect'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'QT_BINPATH'},{'id': '44', 'type': 'call', 'children': ['45', '50']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': "'$QTDIR'"},{'id': '52', 'type': 'string', 'children': [], 'value': "'bin'"},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'QT_CPPPATH'},{'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': 'os'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'$QTDIR'"},{'id': '63', 'type': 'string', 'children': [], 'value': "'include'"},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'QT_LIBPATH'},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "'$QTDIR'"},{'id': '74', 'type': 'string', 'children': [], 'value': "'lib'"},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'QT_MOC'},{'id': '77', 'type': 'call', 'children': ['78', '83']},{'id': '78', 'type': 'attribute', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': "'$QT_BINPATH'"},{'id': '85', 'type': 'string', 'children': [], 'value': "'moc'"},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'QT_UIC'},{'id': '88', 'type': 'call', 'children': ['89', '94']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': "'$QT_BINPATH'"},{'id': '96', 'type': 'string', 'children': [], 'value': "'uic'"},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'QT_LIB'},{'id': '99', 'type': 'string', 'children': [], 'value': "'qt'"},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'QT_AUTOSCAN'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'QT_UICIMPLFLAGS'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'CLVar'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': "''"},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'QT_UICDECLFLAGS'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'CLVar'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'string', 'children': [], 'value': "''"},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'QT_MOCFROMHFLAGS'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'CLVar'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': "''"},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'QT_MOCFROMCXXFLAGS'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'CLVar'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'string', 'children': [], 'value': "'-i'"},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'QT_UICDECLPREFIX'},{'id': '129', 'type': 'string', 'children': [], 'value': "''"},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'QT_UICDECLSUFFIX'},{'id': '132', 'type': 'string', 'children': [], 'value': "'.h'"},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'QT_UICIMPLPREFIX'},{'id': '135', 'type': 'string', 'children': [], 'value': "'uic_'"},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'QT_UICIMPLSUFFIX'},{'id': '138', 'type': 'string', 'children': [], 'value': "'$CXXFILESUFFIX'"},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'QT_MOCHPREFIX'},{'id': '141', 'type': 'string', 'children': [], 'value': "'moc_'"},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'QT_MOCHSUFFIX'},{'id': '144', 'type': 'string', 'children': [], 'value': "'$CXXFILESUFFIX'"},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'QT_MOCCXXPREFIX'},{'id': '147', 'type': 'string', 'children': [], 'value': "''"},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'QT_MOCCXXSUFFIX'},{'id': '150', 'type': 'string', 'children': [], 'value': "'.moc'"},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'QT_UISUFFIX'},{'id': '153', 'type': 'string', 'children': [], 'value': "'.ui'"},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'QT_UICCOM'},{'id': '156', 'type': 'list', 'children': ['157', '161', '167'], 'value': "[\n CLVar('$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE'),\n CLVar('$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} '\n '-o ${TARGETS[1]} $SOURCE'),\n CLVar('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}')]"},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'CLVar'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'string', 'children': [], 'value': "'$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE'"},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'CLVar'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'concatenated_string', 'children': ['165', '166']},{'id': '165', 'type': 'string', 'children': [], 'value': "'$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} '"},{'id': '166', 'type': 'string', 'children': [], 'value': "'-o ${TARGETS[1]} $SOURCE'"},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'CLVar'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'string', 'children': [], 'value': "'$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}'"},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'QT_MOCFROMHCOM'},{'id': '173', 'type': '()', 'children': ['174']},{'id': '174', 'type': 'string', 'children': [], 'value': "'$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE'"},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'QT_MOCFROMCXXCOM'},{'id': '177', 'type': 'list', 'children': ['178', '182'], 'value': "[\n CLVar('$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'),\n Action(checkMocIncluded,None)]"},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'CLVar'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'string', 'children': [], 'value': "'$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'"},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'checkMocIncluded'},{'id': '186', 'type': 'None', 'children': []},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'uicBld'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'Builder'},{'id': '192', 'type': 'argument_list', 'children': ['193', '204', '207', '210', '213', '216']},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '195', 'type': 'call', 'children': ['196', '201']},{'id': '196', 'type': 'attribute', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '201', 'type': 'argument_list', 'children': ['202', '203']},{'id': '202', 'type': 'string', 'children': [], 'value': "'$QT_UICCOM'"},{'id': '203', 'type': 'string', 'children': [], 'value': "'$QT_UICCOMSTR'"},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'emitter'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'uicEmitter'},{'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'src_suffix'},{'id': '209', 'type': 'string', 'children': [], 'value': "'$QT_UISUFFIX'"},{'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '212', 'type': 'string', 'children': [], 'value': "'$QT_UICDECLSUFFIX'"},{'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '215', 'type': 'string', 'children': [], 'value': "'$QT_UICDECLPREFIX'"},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'source_scanner'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'uicScanner'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'mocBld'},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'Builder'},{'id': '224', 'type': 'argument_list', 'children': ['225', '228', '231']},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '227', 'type': 'dictionary', 'children': []},{'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '230', 'type': 'dictionary', 'children': []},{'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '233', 'type': 'dictionary', 'children': []},{'id': '234', 'type': 'for_statement', 'children': ['235', '236', '237']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'header_extensions'},{'id': '237', 'type': 'block', 'children': ['238', '250', '258', '266']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'act'},{'id': '241', 'type': 'call', 'children': ['242', '247']},{'id': '242', 'type': 'attribute', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249']},{'id': '248', 'type': 'string', 'children': [], 'value': "'$QT_MOCFROMHCOM'"},{'id': '249', 'type': 'string', 'children': [], 'value': "'$QT_MOCFROMHCOMSTR'"},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'mocBld'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'add_action'},{'id': '255', 'type': 'argument_list', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'act'},{'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': 'mocBld'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '265', 'type': 'string', 'children': [], 'value': "'$QT_MOCHPREFIX'"},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '273']},{'id': '268', 'type': 'subscript', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'mocBld'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '273', 'type': 'string', 'children': [], 'value': "'$QT_MOCHSUFFIX'"},{'id': '274', 'type': 'for_statement', 'children': ['275', '276', '277']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'cxx'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'cxx_suffixes'},{'id': '277', 'type': 'block', 'children': ['278', '290', '298', '306']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'act'},{'id': '281', 'type': 'call', 'children': ['282', '287']},{'id': '282', 'type': 'attribute', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '287', 'type': 'argument_list', 'children': ['288', '289']},{'id': '288', 'type': 'string', 'children': [], 'value': "'$QT_MOCFROMCXXCOM'"},{'id': '289', 'type': 'string', 'children': [], 'value': "'$QT_MOCFROMCXXCOMSTR'"},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'mocBld'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'add_action'},{'id': '295', 'type': 'argument_list', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'cxx'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'act'},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '305']},{'id': '300', 'type': 'subscript', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'mocBld'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'cxx'},{'id': '305', 'type': 'string', 'children': [], 'value': "'$QT_MOCCXXPREFIX'"},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '313']},{'id': '308', 'type': 'subscript', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'mocBld'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'cxx'},{'id': '313', 'type': 'string', 'children': [], 'value': "'$QT_MOCCXXSUFFIX'"},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '321']},{'id': '316', 'type': 'subscript', 'children': ['317', '320']},{'id': '317', 'type': 'subscript', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '319', 'type': 'string', 'children': [], 'value': "'BUILDERS'"},{'id': '320', 'type': 'string', 'children': [], 'value': "'Uic'"},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'uicBld'},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'assignment', 'children': ['324', '329']},{'id': '324', 'type': 'subscript', 'children': ['325', '328']},{'id': '325', 'type': 'subscript', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '327', 'type': 'string', 'children': [], 'value': "'BUILDERS'"},{'id': '328', 'type': 'string', 'children': [], 'value': "'Moc'"},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'mocBld'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '335']},{'id': '332', 'type': 'pattern_list', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'static_obj'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'shared_obj'},{'id': '335', 'type': 'call', 'children': ['336', '341']},{'id': '336', 'type': 'attribute', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'Tool'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'createObjBuilders'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'env'},{'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': 'static_obj'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'add_src_builder'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'string', 'children': [], 'value': "'Uic'"},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'shared_obj'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'add_src_builder'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'string', 'children': [], 'value': "'Uic'"},{'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': 'env'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'AppendUnique'},{'id': '362', 'type': 'argument_list', 'children': ['363', '367', '371', '375', '379', '383', '387']},{'id': '363', 'type': 'keyword_argument', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'PROGEMITTER'},{'id': '365', 'type': 'list', 'children': ['366'], 'value': '[AutomocStatic]'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'AutomocStatic'},{'id': '367', 'type': 'keyword_argument', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'SHLIBEMITTER'},{'id': '369', 'type': 'list', 'children': ['370'], 'value': '[AutomocShared]'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'AutomocShared'},{'id': '371', 'type': 'keyword_argument', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'LDMODULEEMITTER'},{'id': '373', 'type': 'list', 'children': ['374'], 'value': '[AutomocShared]'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'AutomocShared'},{'id': '375', 'type': 'keyword_argument', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'LIBEMITTER'},{'id': '377', 'type': 'list', 'children': ['378'], 'value': '[AutomocStatic]'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'AutomocStatic'},{'id': '379', 'type': 'keyword_argument', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'CPPPATH'},{'id': '381', 'type': 'list', 'children': ['382'], 'value': '["$QT_CPPPATH"]'},{'id': '382', 'type': 'string', 'children': [], 'value': '"$QT_CPPPATH"'},{'id': '383', 'type': 'keyword_argument', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'LIBPATH'},{'id': '385', 'type': 'list', 'children': ['386'], 'value': '["$QT_LIBPATH"]'},{'id': '386', 'type': 'string', 'children': [], 'value': '"$QT_LIBPATH"'},{'id': '387', 'type': 'keyword_argument', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'LIBS'},{'id': '389', 'type': 'list', 'children': ['390'], 'value': "['$QT_LIB']"},{'id': '390', 'type': 'string', 'children': [], 'value': "'$QT_LIB'"}
def generate(env): CLVar = SCons.Util.CLVar Action = SCons.Action.Action Builder = SCons.Builder.Builder env.SetDefault(QTDIR = _detect(env), QT_BINPATH = os.path.join('$QTDIR', 'bin'), QT_CPPPATH = os.path.join('$QTDIR', 'include'), QT_LIBPATH = os.path.join('$QTDIR', 'lib'), QT_MOC = os.path.join('$QT_BINPATH','moc'), QT_UIC = os.path.join('$QT_BINPATH','uic'), QT_LIB = 'qt', QT_AUTOSCAN = 1, QT_UICIMPLFLAGS = CLVar(''), QT_UICDECLFLAGS = CLVar(''), QT_MOCFROMHFLAGS = CLVar(''), QT_MOCFROMCXXFLAGS = CLVar('-i'), QT_UICDECLPREFIX = '', QT_UICDECLSUFFIX = '.h', QT_UICIMPLPREFIX = 'uic_', QT_UICIMPLSUFFIX = '$CXXFILESUFFIX', QT_MOCHPREFIX = 'moc_', QT_MOCHSUFFIX = '$CXXFILESUFFIX', QT_MOCCXXPREFIX = '', QT_MOCCXXSUFFIX = '.moc', QT_UISUFFIX = '.ui', QT_UICCOM = [ CLVar('$QT_UIC $QT_UICDECLFLAGS -o ${TARGETS[0]} $SOURCE'), CLVar('$QT_UIC $QT_UICIMPLFLAGS -impl ${TARGETS[0].file} ' '-o ${TARGETS[1]} $SOURCE'), CLVar('$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[2]} ${TARGETS[0]}')], QT_MOCFROMHCOM = ( '$QT_MOC $QT_MOCFROMHFLAGS -o ${TARGETS[0]} $SOURCE'), QT_MOCFROMCXXCOM = [ CLVar('$QT_MOC $QT_MOCFROMCXXFLAGS -o ${TARGETS[0]} $SOURCE'), Action(checkMocIncluded,None)]) uicBld = Builder(action=SCons.Action.Action('$QT_UICCOM', '$QT_UICCOMSTR'), emitter=uicEmitter, src_suffix='$QT_UISUFFIX', suffix='$QT_UICDECLSUFFIX', prefix='$QT_UICDECLPREFIX', source_scanner=uicScanner) mocBld = Builder(action={}, prefix={}, suffix={}) for h in header_extensions: act = SCons.Action.Action('$QT_MOCFROMHCOM', '$QT_MOCFROMHCOMSTR') mocBld.add_action(h, act) mocBld.prefix[h] = '$QT_MOCHPREFIX' mocBld.suffix[h] = '$QT_MOCHSUFFIX' for cxx in cxx_suffixes: act = SCons.Action.Action('$QT_MOCFROMCXXCOM', '$QT_MOCFROMCXXCOMSTR') mocBld.add_action(cxx, act) mocBld.prefix[cxx] = '$QT_MOCCXXPREFIX' mocBld.suffix[cxx] = '$QT_MOCCXXSUFFIX' env['BUILDERS']['Uic'] = uicBld env['BUILDERS']['Moc'] = mocBld static_obj, shared_obj = SCons.Tool.createObjBuilders(env) static_obj.add_src_builder('Uic') shared_obj.add_src_builder('Uic') env.AppendUnique(PROGEMITTER =[AutomocStatic], SHLIBEMITTER=[AutomocShared], LDMODULEEMITTER=[AutomocShared], LIBEMITTER =[AutomocStatic], CPPPATH=["$QT_CPPPATH"], LIBPATH=["$QT_LIBPATH"], LIBS=['$QT_LIB'])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'emit_rmic_classes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '7', 'type': 'block', 'children': ['8', '18', '27', '65', '78', '103', '107', '214', '219', '236', '240', '297']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'class_suffix'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': "'JAVACLASSSUFFIX'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'.class'"},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'string', 'children': [], 'value': "'JAVACLASSDIR'"},{'id': '27', 'type': 'if_statement', 'children': ['28', '30']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'try_statement', 'children': ['32', '39', '46']},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'except_clause', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'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': 'classdir'},{'id': '45', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'try_statement', 'children': ['49', '58']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'java_classdir'},{'id': '58', 'type': 'except_clause', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'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': 'classdir'},{'id': '64', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '68', 'type': 'call', 'children': ['69', '77']},{'id': '69', 'type': 'attribute', 'children': ['70', '76']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'Dir'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'rdir'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'if_statement', 'children': ['79', '85', '90']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '84'], 'value': '=='},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '84', 'type': 'string', 'children': [], 'value': "'.'"},{'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': 'c_'},{'id': '89', 'type': 'None', 'children': []},{'id': '90', 'type': 'else_clause', 'children': ['91']},{'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': 'c_'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '100'], 'value': '+'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'slist'},{'id': '106', 'type': 'list', 'children': [], 'value': '[]'},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '110', 'type': 'block', 'children': ['111', '183', '191', '199', '207']},{'id': '111', 'type': 'try_statement', 'children': ['112', '121']},{'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': 'classname'},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'java_classname'},{'id': '121', 'type': 'except_clause', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '123', 'type': 'block', 'children': ['124', '131', '156']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'classname'},{'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': 'src'},{'id': '131', 'type': 'if_statement', 'children': ['132', '144']},{'id': '132', 'type': 'boolean_operator', 'children': ['133', '134'], 'value': 'and'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'c_'},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '143'], 'value': '=='},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '137', 'type': 'slice', 'children': ['138', '139']},{'id': '138', 'type': 'colon', 'children': []},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'c_'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'c_'},{'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': 'classname'},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '150', 'type': 'slice', 'children': ['151', '155']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'c_'},{'id': '155', 'type': 'colon', 'children': []},{'id': '156', 'type': 'if_statement', 'children': ['157', '170']},{'id': '157', 'type': 'boolean_operator', 'children': ['158', '159'], 'value': 'and'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'class_suffix'},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '169'], 'value': '=='},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '162', 'type': 'slice', 'children': ['163', '164']},{'id': '163', 'type': 'colon', 'children': []},{'id': '164', 'type': 'unary_operator', 'children': ['165'], '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': 'class_suffix'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'class_suffix'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '176', 'type': 'slice', 'children': ['177', '182']},{'id': '177', 'type': 'unary_operator', 'children': ['178'], 'value': '-'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'class_suffix'},{'id': '182', 'type': 'colon', 'children': []},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'rfile'},{'id': '190', 'type': 'argument_list', 'children': []},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '198']},{'id': '193', 'type': 'attribute', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'java_classdir'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '206']},{'id': '201', 'type': 'attribute', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'java_classname'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'classname'},{'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': 'slist'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'stub_suffixes'},{'id': '217', 'type': 'list', 'children': ['218'], 'value': "['_Stub']"},{'id': '218', 'type': 'string', 'children': [], 'value': "'_Stub'"},{'id': '219', 'type': 'if_statement', 'children': ['220', '228']},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '227'], 'value': '=='},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'string', 'children': [], 'value': "'JAVAVERSION'"},{'id': '227', 'type': 'string', 'children': [], 'value': "'1.4'"},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'stub_suffixes'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'string', 'children': [], 'value': "'_Skel'"},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'tlist'},{'id': '239', 'type': 'list', 'children': [], 'value': '[]'},{'id': '240', 'type': 'for_statement', 'children': ['241', '242', '243']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'for_statement', 'children': ['245', '246', '247']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'suff'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'stub_suffixes'},{'id': '247', 'type': 'block', 'children': ['248', '269', '280', '290']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '251', 'type': 'binary_operator', 'children': ['252', '268'], 'value': '+'},{'id': '252', 'type': 'binary_operator', 'children': ['253', '266', '267'], 'value': '+'},{'id': '253', 'type': 'call', 'children': ['254', '261']},{'id': '254', 'type': 'attribute', 'children': ['255', '260']},{'id': '255', 'type': 'attribute', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'java_classname'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '266', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'suff'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'class_suffix'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '272', 'type': 'call', 'children': ['273', '278']},{'id': '273', 'type': 'attribute', 'children': ['274', '277']},{'id': '274', 'type': 'subscript', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '276', 'type': 'integer', 'children': [], 'value': '0'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'assignment', 'children': ['282', '287']},{'id': '282', 'type': 'attribute', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'java_lookupdir'},{'id': '287', 'type': 'subscript', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '289', 'type': 'integer', 'children': [], 'value': '0'},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'tlist'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '297', 'type': 'return_statement', 'children': ['298']},{'id': '298', 'type': 'expression_list', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'tlist'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'source'}
def emit_rmic_classes(target, source, env): class_suffix = env.get('JAVACLASSSUFFIX', '.class') classdir = env.get('JAVACLASSDIR') if not classdir: try: s = source[0] except IndexError: classdir = '.' else: try: classdir = s.attributes.java_classdir except AttributeError: classdir = '.' classdir = env.Dir(classdir).rdir() if str(classdir) == '.': c_ = None else: c_ = str(classdir) + os.sep slist = [] for src in source: try: classname = src.attributes.java_classname except AttributeError: classname = str(src) if c_ and classname[:len(c_)] == c_: classname = classname[len(c_):] if class_suffix and classname[:-len(class_suffix)] == class_suffix: classname = classname[-len(class_suffix):] s = src.rfile() s.attributes.java_classdir = classdir s.attributes.java_classname = classname slist.append(s) stub_suffixes = ['_Stub'] if env.get('JAVAVERSION') == '1.4': stub_suffixes.append('_Skel') tlist = [] for s in source: for suff in stub_suffixes: fname = s.attributes.java_classname.replace('.', os.sep) + \ suff + class_suffix t = target[0].File(fname) t.attributes.java_lookupdir = target[0] tlist.append(t) return tlist, source
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_probe_services'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '6', 'type': 'block', 'children': ['7', '11', '52', '93', '107', '130', '142', '151', '162', '175', '188', '200', '206', '219', '241', '245', '255']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0x2800'},{'id': '11', 'type': 'function_definition', 'children': ['12', '13', '15']},{'id': '12', 'type': 'function_name', 'children': [], 'value': 'event_filter_func'},{'id': '13', 'type': 'parameters', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '15', 'type': 'block', 'children': ['16', '50']},{'id': '16', 'type': 'if_statement', 'children': ['17', '29']},{'id': '17', 'type': '()', 'children': ['18']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '24'], 'value': 'and'},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '=='},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'command_class'},{'id': '23', 'type': 'integer', 'children': [], 'value': '4'},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': '=='},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '28', 'type': 'integer', 'children': [], 'value': '2'},{'id': '29', 'type': 'block', 'children': ['30', '46']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '34']},{'id': '32', 'type': 'pattern_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'event_handle'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': '"B"'},{'id': '38', 'type': 'subscript', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '42', 'type': 'slice', 'children': ['43', '44', '45']},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'colon', 'children': []},{'id': '45', 'type': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '=='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'event_handle'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'False', 'children': []},{'id': '52', 'type': 'function_definition', 'children': ['53', '54', '56']},{'id': '53', 'type': 'function_name', 'children': [], 'value': 'end_filter_func'},{'id': '54', 'type': 'parameters', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '56', 'type': 'block', 'children': ['57', '91']},{'id': '57', 'type': 'if_statement', 'children': ['58', '70']},{'id': '58', 'type': '()', 'children': ['59']},{'id': '59', 'type': 'boolean_operator', 'children': ['60', '65'], 'value': 'and'},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': '=='},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'command_class'},{'id': '64', 'type': 'integer', 'children': [], 'value': '4'},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': '=='},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'block', 'children': ['71', '87']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '75']},{'id': '73', 'type': 'pattern_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'event_handle'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': '"B"'},{'id': '79', 'type': 'subscript', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '83', 'type': 'slice', 'children': ['84', '85', '86']},{'id': '84', 'type': 'integer', 'children': [], 'value': '0'},{'id': '85', 'type': 'colon', 'children': []},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '=='},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'event_handle'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '91', 'type': 'return_statement', 'children': ['92']},{'id': '92', 'type': 'False', 'children': []},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'struct'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102', '103', '104', '105', '106']},{'id': '101', 'type': 'string', 'children': [], 'value': "'<BHHBH'"},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0xFFFF'},{'id': '105', 'type': 'integer', 'children': [], 'value': '2'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '107', 'type': 'try_statement', 'children': ['108', '120']},{'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': 'response'},{'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': '_send_command'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119']},{'id': '117', 'type': 'integer', 'children': [], 'value': '4'},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '120', 'type': 'except_clause', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'InternalTimeoutError'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'return_statement', 'children': ['124']},{'id': '124', 'type': 'expression_list', 'children': ['125', '126']},{'id': '125', 'type': 'False', 'children': []},{'id': '126', 'type': 'dictionary', 'children': ['127']},{'id': '127', 'type': 'pair', 'children': ['128', '129']},{'id': '128', 'type': 'string', 'children': [], 'value': "'reason'"},{'id': '129', 'type': 'string', 'children': [], 'value': "'Timeout waiting for command response'"},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '135']},{'id': '132', 'type': 'pattern_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'string', 'children': [], 'value': '"<BH"'},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '142', 'type': 'if_statement', 'children': ['143', '146']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': '!='},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'return_statement', 'children': ['148']},{'id': '148', 'type': 'expression_list', 'children': ['149', '150']},{'id': '149', 'type': 'False', 'children': []},{'id': '150', 'type': 'None', 'children': []},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_wait_process_events'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160', '161']},{'id': '159', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'event_filter_func'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'end_filter_func'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'gatt_events'},{'id': '165', 'type': 'list_comprehension', 'children': ['166', '167', '170']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '167', 'type': 'for_in_clause', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '170', 'type': 'if_clause', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'event_filter_func'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'end_events'},{'id': '178', 'type': 'list_comprehension', 'children': ['179', '180', '183']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '180', 'type': 'for_in_clause', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '183', 'type': 'if_clause', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'end_filter_func'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '188', 'type': 'if_statement', 'children': ['189', '195']},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '194'], 'value': '=='},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'end_events'},{'id': '194', 'type': 'integer', 'children': [], 'value': '0'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'return_statement', 'children': ['197']},{'id': '197', 'type': 'expression_list', 'children': ['198', '199']},{'id': '198', 'type': 'False', 'children': []},{'id': '199', 'type': 'None', 'children': []},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'end_event'},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'end_events'},{'id': '205', 'type': 'integer', 'children': [], 'value': '0'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '212']},{'id': '208', 'type': 'pattern_list', 'children': ['209', '210', '211']},{'id': '209', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '211', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216']},{'id': '215', 'type': 'string', 'children': [], 'value': '"<BHH"'},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'end_event'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '219', 'type': 'if_statement', 'children': ['220', '223']},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '222'], 'value': '!='},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '222', 'type': 'integer', 'children': [], 'value': '0'},{'id': '223', 'type': 'block', 'children': ['224', '237']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '231']},{'id': '226', 'type': 'attribute', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '229', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'binary_operator', 'children': ['233', '234'], 'value': '%'},{'id': '233', 'type': 'string', 'children': [], 'value': '"Error enumerating GATT table, protocol error code = %d (0x%X)"'},{'id': '234', 'type': 'tuple', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': 'expression_list', 'children': ['239', '240']},{'id': '239', 'type': 'False', 'children': []},{'id': '240', 'type': 'None', 'children': []},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'services'},{'id': '244', 'type': 'dictionary', 'children': []},{'id': '245', 'type': 'for_statement', 'children': ['246', '247', '248']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'gatt_events'},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'process_gatt_service'},{'id': '252', 'type': 'argument_list', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'services'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '255', 'type': 'return_statement', 'children': ['256']},{'id': '256', 'type': 'expression_list', 'children': ['257', '258']},{'id': '257', 'type': 'True', 'children': []},{'id': '258', 'type': 'dictionary', 'children': ['259']},{'id': '259', 'type': 'pair', 'children': ['260', '261']},{'id': '260', 'type': 'string', 'children': [], 'value': "'services'"},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'services'}
def _probe_services(self, handle): code = 0x2800 def event_filter_func(event): if (event.command_class == 4 and event.command == 2): event_handle, = unpack("B", event.payload[0:1]) return event_handle == handle return False def end_filter_func(event): if (event.command_class == 4 and event.command == 1): event_handle, = unpack("B", event.payload[0:1]) return event_handle == handle return False payload = struct.pack('<BHHBH', handle, 1, 0xFFFF, 2, code) try: response = self._send_command(4, 1, payload) except InternalTimeoutError: return False, {'reason': 'Timeout waiting for command response'} handle, result = unpack("<BH", response.payload) if result != 0: return False, None events = self._wait_process_events(0.5, event_filter_func, end_filter_func) gatt_events = [x for x in events if event_filter_func(x)] end_events = [x for x in events if end_filter_func(x)] if len(end_events) == 0: return False, None end_event = end_events[0] _, result, _ = unpack("<BHH", end_event.payload) if result != 0: self._logger.warn("Error enumerating GATT table, protocol error code = %d (0x%X)" % (result, result)) return False, None services = {} for event in gatt_events: process_gatt_service(services, event) return True, {'services': services}
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_write_handle'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ack'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '11', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '12', 'type': 'block', 'children': ['13', '17', '21', '60', '67', '79', '94', '133', '145', '160', '222']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'conn_handle'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'char_handle'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '21', 'type': 'function_definition', 'children': ['22', '23', '25']},{'id': '22', 'type': 'function_name', 'children': [], 'value': 'write_handle_acked'},{'id': '23', 'type': 'parameters', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '38']},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '33'], 'value': 'and'},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': '=='},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'command_class'},{'id': '32', 'type': 'integer', 'children': [], 'value': '4'},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': '=='},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'block', 'children': ['39', '52']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '45']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43', '44']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': '"<BHH"'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'boolean_operator', 'children': ['54', '57'], 'value': 'and'},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': '=='},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'conn_handle'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'conn'},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': '=='},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'char_handle'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'data_len'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '>'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'data_len'},{'id': '70', 'type': 'integer', 'children': [], 'value': '20'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'return_statement', 'children': ['73']},{'id': '73', 'type': 'expression_list', 'children': ['74', '75']},{'id': '74', 'type': 'False', 'children': []},{'id': '75', 'type': 'dictionary', 'children': ['76']},{'id': '76', 'type': 'pair', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': "'reason'"},{'id': '78', 'type': 'string', 'children': [], 'value': "'Data too long to write'"},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'struct'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '86', 'type': 'argument_list', 'children': ['87', '90', '91', '92', '93']},{'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '%'},{'id': '88', 'type': 'string', 'children': [], 'value': '"<BHB%ds"'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'data_len'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'conn_handle'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'char_handle'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'data_len'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '94', 'type': 'try_statement', 'children': ['95', '123']},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'if_statement', 'children': ['97', '98', '110']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'ack'},{'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': 'response'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_send_command'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108', '109']},{'id': '107', 'type': 'integer', 'children': [], 'value': '4'},{'id': '108', 'type': 'integer', 'children': [], 'value': '5'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '110', 'type': 'else_clause', 'children': ['111']},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': '_send_command'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121', '122']},{'id': '120', 'type': 'integer', 'children': [], 'value': '4'},{'id': '121', 'type': 'integer', 'children': [], 'value': '6'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '123', 'type': 'except_clause', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'InternalTimeoutError'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'expression_list', 'children': ['128', '129']},{'id': '128', 'type': 'False', 'children': []},{'id': '129', 'type': 'dictionary', 'children': ['130']},{'id': '130', 'type': 'pair', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': "'reason'"},{'id': '132', 'type': 'string', 'children': [], 'value': "'Timeout waiting for response to command in _write_handle'"},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '138']},{'id': '135', 'type': 'pattern_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': '"<BH"'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '145', 'type': 'if_statement', 'children': ['146', '149']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '!='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'expression_list', 'children': ['152', '153']},{'id': '152', 'type': 'False', 'children': []},{'id': '153', 'type': 'dictionary', 'children': ['154', '157']},{'id': '154', 'type': 'pair', 'children': ['155', '156']},{'id': '155', 'type': 'string', 'children': [], 'value': "'reason'"},{'id': '156', 'type': 'string', 'children': [], 'value': "'Error writing to handle'"},{'id': '157', 'type': 'pair', 'children': ['158', '159']},{'id': '158', 'type': 'string', 'children': [], 'value': "'error_code'"},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '160', 'type': 'if_statement', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ack'},{'id': '162', 'type': 'block', 'children': ['163', '177', '192', '207']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '_wait_process_events'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172', '176']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '172', 'type': 'lambda', 'children': ['173', '175']},{'id': '173', 'type': 'lambda_parameters', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '175', 'type': 'False', 'children': []},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'write_handle_acked'},{'id': '177', 'type': 'if_statement', 'children': ['178', '184']},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '183'], 'value': '=='},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '183', 'type': 'integer', 'children': [], 'value': '0'},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'return_statement', 'children': ['186']},{'id': '186', 'type': 'expression_list', 'children': ['187', '188']},{'id': '187', 'type': 'False', 'children': []},{'id': '188', 'type': 'dictionary', 'children': ['189']},{'id': '189', 'type': 'pair', 'children': ['190', '191']},{'id': '190', 'type': 'string', 'children': [], 'value': "'reason'"},{'id': '191', 'type': 'string', 'children': [], 'value': "'Timeout waiting for acknowledge on write'"},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '198']},{'id': '194', 'type': 'pattern_list', 'children': ['195', '196', '197']},{'id': '195', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '197', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': '"<BHH"'},{'id': '202', 'type': 'attribute', 'children': ['203', '206']},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '205', 'type': 'integer', 'children': [], 'value': '0'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '207', 'type': 'if_statement', 'children': ['208', '211']},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '210'], 'value': '!='},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '210', 'type': 'integer', 'children': [], 'value': '0'},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'return_statement', 'children': ['213']},{'id': '213', 'type': 'expression_list', 'children': ['214', '215']},{'id': '214', 'type': 'False', 'children': []},{'id': '215', 'type': 'dictionary', 'children': ['216', '219']},{'id': '216', 'type': 'pair', 'children': ['217', '218']},{'id': '217', 'type': 'string', 'children': [], 'value': "'reason'"},{'id': '218', 'type': 'string', 'children': [], 'value': "'Error received during write to handle'"},{'id': '219', 'type': 'pair', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': "'error_code'"},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '222', 'type': 'return_statement', 'children': ['223']},{'id': '223', 'type': 'expression_list', 'children': ['224', '225']},{'id': '224', 'type': 'True', 'children': []},{'id': '225', 'type': 'None', 'children': []}
def _write_handle(self, conn, handle, ack, value, timeout=1.0): conn_handle = conn char_handle = handle def write_handle_acked(event): if event.command_class == 4 and event.command == 1: conn, _, char = unpack("<BHH", event.payload) return conn_handle == conn and char_handle == char data_len = len(value) if data_len > 20: return False, {'reason': 'Data too long to write'} payload = struct.pack("<BHB%ds" % data_len, conn_handle, char_handle, data_len, value) try: if ack: response = self._send_command(4, 5, payload) else: response = self._send_command(4, 6, payload) except InternalTimeoutError: return False, {'reason': 'Timeout waiting for response to command in _write_handle'} _, result = unpack("<BH", response.payload) if result != 0: return False, {'reason': 'Error writing to handle', 'error_code': result} if ack: events = self._wait_process_events(timeout, lambda x: False, write_handle_acked) if len(events) == 0: return False, {'reason': 'Timeout waiting for acknowledge on write'} _, result, _ = unpack("<BHH", events[0].payload) if result != 0: return False, {'reason': 'Error received during write to handle', 'error_code': result} return True, None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_specfiles'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '7', 'type': 'block', 'children': ['8', '12', '70', '78', '103', '117', '155', '200', '217', '231']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'opened_files'},{'id': '11', 'type': 'dictionary', 'children': []},{'id': '12', 'type': 'function_definition', 'children': ['13', '14', '17']},{'id': '13', 'type': 'function_name', 'children': [], 'value': 'open_file'},{'id': '14', 'type': 'parameters', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'needle'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'haystack'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'try_statement', 'children': ['19', '24']},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'opened_files'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'needle'},{'id': '24', 'type': 'except_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '26', 'type': 'block', 'children': ['27', '52', '66']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '30', 'type': 'subscript', 'children': ['31', '51']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '33', 'type': 'argument_list', 'children': ['34', '50']},{'id': '34', 'type': 'lambda', 'children': ['35', '37']},{'id': '35', 'type': 'lambda_parameters', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '48'], 'value': '!='},{'id': '38', 'type': 'call', 'children': ['39', '46']},{'id': '39', 'type': 'attribute', 'children': ['40', '45']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_path'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'rfind'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'needle'},{'id': '48', 'type': 'unary_operator', 'children': ['49'], 'value': '-'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'haystack'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '57']},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'opened_files'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'needle'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '59', 'type': 'argument_list', 'children': ['60', '65']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get_abspath'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'opened_files'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'needle'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'control_file'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'open_file'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': "'control'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '78', 'type': 'if_statement', 'children': ['79', '82']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'not'},{'id': '80', 'type': 'string', 'children': [], 'value': "'X_IPK_DESCRIPTION'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '88']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '87', 'type': 'string', 'children': [], 'value': "'X_IPK_DESCRIPTION'"},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '%'},{'id': '89', 'type': 'string', 'children': [], 'value': '"%s\\n %s"'},{'id': '90', 'type': 'tuple', 'children': ['91', '94']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '93', 'type': 'string', 'children': [], 'value': "'SUMMARY'"},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '98', 'type': 'string', 'children': [], 'value': "'DESCRIPTION'"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '102', 'type': 'string', 'children': [], 'value': "'\\n '"},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'control_file'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '117', 'type': 'for_statement', 'children': ['118', '119', '131']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '119', 'type': 'list_comprehension', 'children': ['120', '121', '124']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '121', 'type': 'for_in_clause', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '124', 'type': 'if_clause', 'children': ['125']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'in'},{'id': '126', 'type': 'string', 'children': [], 'value': "'PACKAGING_CONFIG'"},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '131', 'type': 'block', 'children': ['132', '139', '148']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'open_file'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'string', 'children': [], 'value': "'conffiles'"},{'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': 'config'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'PACKAGING_INSTALL_LOCATION'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '155', 'type': 'for_statement', 'children': ['156', '157', '162']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': "'POSTRM PRERM POSTINST PREINST'"},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'block', 'children': ['163', '169']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '%'},{'id': '167', 'type': 'string', 'children': [], 'value': '"PACKAGING_X_IPK_%s"'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '183']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '171', 'type': 'list_comprehension', 'children': ['172', '173', '176']},{'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': 'identifier', 'children': [], 'value': 'source'},{'id': '176', 'type': 'if_clause', 'children': ['177']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'in'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '183', 'type': 'block', 'children': ['184', '191']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'open_file'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'file'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '200', 'type': 'for_statement', 'children': ['201', '202', '210']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'opened_files'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'block', 'children': ['211']},{'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': 'f'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '216', 'type': 'argument_list', 'children': []},{'id': '217', 'type': 'if_statement', 'children': ['218', '221']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'in'},{'id': '219', 'type': 'string', 'children': [], 'value': "'CHANGE_SPECFILE'"},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'augmented_assignment', 'children': ['224', '225'], 'value': '+='},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '228', 'type': 'string', 'children': [], 'value': "'CHANGE_SPECFILE'"},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '231', 'type': 'return_statement', 'children': ['232']},{'id': '232', 'type': 'integer', 'children': [], 'value': '0'}
def build_specfiles(source, target, env): opened_files={} def open_file(needle, haystack): try: return opened_files[needle] except KeyError: file=filter(lambda x: x.get_path().rfind(needle)!=-1, haystack)[0] opened_files[needle]=open(file.get_abspath(), 'w') return opened_files[needle] control_file=open_file('control', target) if 'X_IPK_DESCRIPTION' not in env: env['X_IPK_DESCRIPTION']="%s\n %s"%(env['SUMMARY'], env['DESCRIPTION'].replace('\n', '\n ')) content = control_file.write(env.subst(content)) for f in [x for x in source if 'PACKAGING_CONFIG' in dir(x)]: config=open_file('conffiles') config.write(f.PACKAGING_INSTALL_LOCATION) config.write('\n') for str in 'POSTRM PRERM POSTINST PREINST'.split(): name="PACKAGING_X_IPK_%s"%str for f in [x for x in source if name in dir(x)]: file=open_file(name) file.write(env[str]) for f in list(opened_files.values()): f.close() if 'CHANGE_SPECFILE' in env: content += env['CHANGE_SPECFILE'](target) return 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'emit_java_headers'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '7', 'type': 'block', 'children': ['8', '18', '27', '65', '78', '103', '107', '219', '229', '247', '358']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'class_suffix'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': "'JAVACLASSSUFFIX'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'.class'"},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'string', 'children': [], 'value': "'JAVACLASSDIR'"},{'id': '27', 'type': 'if_statement', 'children': ['28', '30']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'try_statement', 'children': ['32', '39', '46']},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'except_clause', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'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': 'classdir'},{'id': '45', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'try_statement', 'children': ['49', '58']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'java_classdir'},{'id': '58', 'type': 'except_clause', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'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': 'classdir'},{'id': '64', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '68', 'type': 'call', 'children': ['69', '77']},{'id': '69', 'type': 'attribute', 'children': ['70', '76']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'Dir'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'rdir'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'if_statement', 'children': ['79', '85', '90']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '84'], 'value': '=='},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '84', 'type': 'string', 'children': [], 'value': "'.'"},{'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': 'c_'},{'id': '89', 'type': 'None', 'children': []},{'id': '90', 'type': 'else_clause', 'children': ['91']},{'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': 'c_'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '100'], 'value': '+'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'slist'},{'id': '106', 'type': 'list', 'children': [], 'value': '[]'},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '110', 'type': 'block', 'children': ['111', '196', '204', '212']},{'id': '111', 'type': 'try_statement', 'children': ['112', '121']},{'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': 'classname'},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'java_classname'},{'id': '121', 'type': 'except_clause', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '123', 'type': 'block', 'children': ['124', '131', '156', '183']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'classname'},{'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': 'src'},{'id': '131', 'type': 'if_statement', 'children': ['132', '144']},{'id': '132', 'type': 'boolean_operator', 'children': ['133', '134'], 'value': 'and'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'c_'},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '143'], 'value': '=='},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '137', 'type': 'slice', 'children': ['138', '139']},{'id': '138', 'type': 'colon', 'children': []},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'c_'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'c_'},{'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': 'classname'},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '150', 'type': 'slice', 'children': ['151', '155']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'c_'},{'id': '155', 'type': 'colon', 'children': []},{'id': '156', 'type': 'if_statement', 'children': ['157', '170']},{'id': '157', 'type': 'boolean_operator', 'children': ['158', '159'], 'value': 'and'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'class_suffix'},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '169'], 'value': '=='},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '162', 'type': 'slice', 'children': ['163', '168']},{'id': '163', 'type': 'unary_operator', 'children': ['164'], 'value': '-'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'class_suffix'},{'id': '168', 'type': 'colon', 'children': []},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'class_suffix'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '176', 'type': 'slice', 'children': ['177', '178']},{'id': '177', 'type': 'colon', 'children': []},{'id': '178', 'type': 'unary_operator', 'children': ['179'], 'value': '-'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'class_suffix'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '186', 'type': 'call', 'children': ['187', '194']},{'id': '187', 'type': 'attribute', 'children': ['188', '193']},{'id': '188', 'type': 'attribute', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'Tool'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'javac'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'rfile'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '211']},{'id': '206', 'type': 'attribute', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'java_classname'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'slist'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '222', 'type': 'call', 'children': ['223', '228']},{'id': '223', 'type': 'attribute', 'children': ['224', '227']},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '226', 'type': 'integer', 'children': [], 'value': '0'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'rfile'},{'id': '228', 'type': 'argument_list', 'children': []},{'id': '229', 'type': 'if_statement', 'children': ['230', '238']},{'id': '230', 'type': 'not_operator', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '233', 'type': 'argument_list', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '237', 'type': 'string', 'children': [], 'value': "'java_classdir'"},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '246']},{'id': '241', 'type': 'attribute', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'java_classdir'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'classdir'},{'id': '247', 'type': 'if_statement', 'children': ['248', '261', '266']},{'id': '248', 'type': 'comparison_operator', 'children': ['249', '254'], 'value': 'is'},{'id': '249', 'type': 'attribute', 'children': ['250', '253']},{'id': '250', 'type': 'subscript', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '252', 'type': 'integer', 'children': [], 'value': '0'},{'id': '253', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '254', 'type': 'attribute', 'children': ['255', '260']},{'id': '255', 'type': 'attribute', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'FS'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '261', 'type': 'block', 'children': ['262']},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'tlist'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '266', 'type': 'else_clause', 'children': ['267']},{'id': '267', 'type': 'block', 'children': ['268', '306', '310']},{'id': '268', 'type': 'if_statement', 'children': ['269', '283']},{'id': '269', 'type': 'not_operator', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '272', 'type': 'argument_list', 'children': ['273', '276']},{'id': '273', 'type': 'subscript', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '275', 'type': 'integer', 'children': [], 'value': '0'},{'id': '276', 'type': 'attribute', 'children': ['277', '282']},{'id': '277', 'type': 'attribute', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'FS'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'Dir'},{'id': '283', 'type': 'block', 'children': ['284', '298']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '291']},{'id': '286', 'type': 'attribute', 'children': ['287', '290']},{'id': '287', 'type': 'subscript', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '289', 'type': 'integer', 'children': [], 'value': '0'},{'id': '290', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '291', 'type': 'attribute', 'children': ['292', '297']},{'id': '292', 'type': 'attribute', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'FS'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'Dir'},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '305']},{'id': '300', 'type': 'attribute', 'children': ['301', '304']},{'id': '301', 'type': 'subscript', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '303', 'type': 'integer', 'children': [], 'value': '0'},{'id': '304', 'type': 'identifier', 'children': [], 'value': '_morph'},{'id': '305', 'type': 'argument_list', 'children': []},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'tlist'},{'id': '309', 'type': 'list', 'children': [], 'value': '[]'},{'id': '310', 'type': 'for_statement', 'children': ['311', '312', '313']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '313', 'type': 'block', 'children': ['314', '330', '341', '351']},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '317', 'type': 'binary_operator', 'children': ['318', '329'], 'value': '+'},{'id': '318', 'type': 'call', 'children': ['319', '326']},{'id': '319', 'type': 'attribute', 'children': ['320', '325']},{'id': '320', 'type': 'attribute', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'java_classname'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '326', 'type': 'argument_list', 'children': ['327', '328']},{'id': '327', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '328', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '329', 'type': 'string', 'children': [], 'value': "'.h'"},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '333', 'type': 'call', 'children': ['334', '339']},{'id': '334', 'type': 'attribute', 'children': ['335', '338']},{'id': '335', 'type': 'subscript', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '337', 'type': 'integer', 'children': [], 'value': '0'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '339', 'type': 'argument_list', 'children': ['340']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'assignment', 'children': ['343', '348']},{'id': '343', 'type': 'attribute', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'java_lookupdir'},{'id': '348', 'type': 'subscript', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '350', 'type': 'integer', 'children': [], 'value': '0'},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'tlist'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '358', 'type': 'return_statement', 'children': ['359']},{'id': '359', 'type': 'expression_list', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'tlist'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'source'}
def emit_java_headers(target, source, env): class_suffix = env.get('JAVACLASSSUFFIX', '.class') classdir = env.get('JAVACLASSDIR') if not classdir: try: s = source[0] except IndexError: classdir = '.' else: try: classdir = s.attributes.java_classdir except AttributeError: classdir = '.' classdir = env.Dir(classdir).rdir() if str(classdir) == '.': c_ = None else: c_ = str(classdir) + os.sep slist = [] for src in source: try: classname = src.attributes.java_classname except AttributeError: classname = str(src) if c_ and classname[:len(c_)] == c_: classname = classname[len(c_):] if class_suffix and classname[-len(class_suffix):] == class_suffix: classname = classname[:-len(class_suffix)] classname = SCons.Tool.javac.classname(classname) s = src.rfile() s.attributes.java_classname = classname slist.append(s) s = source[0].rfile() if not hasattr(s.attributes, 'java_classdir'): s.attributes.java_classdir = classdir if target[0].__class__ is SCons.Node.FS.File: tlist = target else: if not isinstance(target[0], SCons.Node.FS.Dir): target[0].__class__ = SCons.Node.FS.Dir target[0]._morph() tlist = [] for s in source: fname = s.attributes.java_classname.replace('.', '_') + '.h' t = target[0].File(fname) t.attributes.java_lookupdir = target[0] tlist.append(t) return tlist, source
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse_resource_usage'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'action_dict'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'declarations'},{'id': '7', 'type': 'block', 'children': ['8', '18', '36', '54', '58', '163', '187', '207', '227']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'raw_used'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'action_dict'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': "'use'"},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'opened'},{'id': '21', 'type': 'list_comprehension', 'children': ['22', '27']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'action_dict'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'open_before'"},{'id': '35', 'type': 'list', 'children': [], 'value': '[]'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'closed'},{'id': '39', 'type': 'list_comprehension', 'children': ['40', '45']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'action_dict'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'close_after'"},{'id': '53', 'type': 'list', 'children': [], 'value': '[]'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'used'},{'id': '57', 'type': 'dictionary', 'children': []},{'id': '58', 'type': 'for_statement', 'children': ['59', '60', '61']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'raw_used'},{'id': '61', 'type': 'block', 'children': ['62', '138', '157']},{'id': '62', 'type': 'if_statement', 'children': ['63', '66', '124']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'in'},{'id': '64', 'type': 'string', 'children': [], 'value': "'as'"},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '66', 'type': 'block', 'children': ['67', '79', '87', '95']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '73']},{'id': '69', 'type': 'pattern_list', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'global_name'},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'local_name'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'string', 'children': [], 'value': "'as'"},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'global_name'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'global_name'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'local_name'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'local_name'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'if_statement', 'children': ['96', '109']},{'id': '96', 'type': 'boolean_operator', 'children': ['97', '103'], 'value': 'or'},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '102'], 'value': '=='},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'global_name'},{'id': '102', 'type': 'integer', 'children': [], 'value': '0'},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '108'], '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': 'identifier', 'children': [], 'value': 'local_name'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'raise_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'RecipeFileInvalid'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115', '118', '121']},{'id': '114', 'type': 'string', 'children': [], 'value': '"Resource usage specified in action with invalid name using \'as\' statement"'},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'global_name'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'global_name'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'local_name'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'local_name'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '124', 'type': 'else_clause', 'children': ['125']},{'id': '125', 'type': 'block', 'children': ['126', '134']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'global_name'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'local_name'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'global_name'},{'id': '138', 'type': 'if_statement', 'children': ['139', '142']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': 'in'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'local_name'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'used'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'raise_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'RecipeFileInvalid'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148', '151', '154']},{'id': '147', 'type': 'string', 'children': [], 'value': '"Resource specified twice for action"'},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'action_dict'},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'local_name'},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'used_resources'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'used'},{'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': 'used'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'local_name'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'global_name'},{'id': '163', 'type': 'for_statement', 'children': ['164', '165', '178']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '165', 'type': 'generator_expression', 'children': ['166', '167', '174']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '167', 'type': 'for_in_clause', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'used'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '173', 'type': 'argument_list', 'children': []},{'id': '174', 'type': 'if_clause', 'children': ['175']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': 'not'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'declarations'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'raise_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'RecipeFileInvalid'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'string', 'children': [], 'value': '"Action makes use of non-declared shared resource"'},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '187', 'type': 'for_statement', 'children': ['188', '189', '198']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '189', 'type': 'generator_expression', 'children': ['190', '191', '194']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '191', 'type': 'for_in_clause', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'opened'},{'id': '194', 'type': 'if_clause', 'children': ['195']},{'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': 'not'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'declarations'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'raise_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'RecipeFileInvalid'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204']},{'id': '203', 'type': 'string', 'children': [], 'value': '"Action specified a non-declared shared resource in open_before"'},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '207', 'type': 'for_statement', 'children': ['208', '209', '218']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '209', 'type': 'generator_expression', 'children': ['210', '211', '214']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '211', 'type': 'for_in_clause', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'closed'},{'id': '214', 'type': 'if_clause', 'children': ['215']},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': 'not'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'declarations'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'raise_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'RecipeFileInvalid'},{'id': '222', 'type': 'argument_list', 'children': ['223', '224']},{'id': '223', 'type': 'string', 'children': [], 'value': '"Action specified a non-declared shared resource in close_after"'},{'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '227', 'type': 'return_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'ResourceUsage'},{'id': '230', 'type': 'argument_list', 'children': ['231', '232', '233']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'used'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'opened'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'closed'}
def _parse_resource_usage(cls, action_dict, declarations): raw_used = action_dict.pop('use', []) opened = [x.strip() for x in action_dict.pop('open_before', [])] closed = [x.strip() for x in action_dict.pop('close_after', [])] used = {} for resource in raw_used: if 'as' in resource: global_name, _, local_name = resource.partition('as') global_name = global_name.strip() local_name = local_name.strip() if len(global_name) == 0 or len(local_name) == 0: raise RecipeFileInvalid("Resource usage specified in action with invalid name using 'as' statement", global_name=global_name, local_name=local_name, statement=resource) else: global_name = resource.strip() local_name = global_name if local_name in used: raise RecipeFileInvalid("Resource specified twice for action", args=action_dict, resource=local_name, used_resources=used) used[local_name] = global_name for name in (x for x in used.values() if x not in declarations): raise RecipeFileInvalid("Action makes use of non-declared shared resource", name=name) for name in (x for x in opened if x not in declarations): raise RecipeFileInvalid("Action specified a non-declared shared resource in open_before", name=name) for name in (x for x in closed if x not in declarations): raise RecipeFileInvalid("Action specified a non-declared shared resource in close_after", name=name) return ResourceUsage(used, opened, closed)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'format_script'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '5', 'type': 'block', 'children': ['6', '10', '23', '35', '47', '69', '88', '129', '141', '150', '212', '223', '234', '254', '261']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'SetGraphOnlineRecord'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '22', 'type': 'integer', 'children': [], 'value': '8'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ClearDataRecord'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '34', 'type': 'integer', 'children': [], 'value': '8'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ResetGraphRecord'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '46', 'type': 'integer', 'children': [], 'value': '8'},{'id': '47', 'type': 'for_statement', 'children': ['48', '49', '52']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'AddNodeRecord'},{'id': '61', 'type': 'argument_list', 'children': ['62', '66']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '68', 'type': 'integer', 'children': [], 'value': '8'},{'id': '69', 'type': 'for_statement', 'children': ['70', '71', '74']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'streamers'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'AddStreamerRecord'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'streamer'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '87', 'type': 'integer', 'children': [], 'value': '8'},{'id': '88', 'type': 'for_statement', 'children': ['89', '92', '114']},{'id': '89', 'type': 'pattern_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '94', 'type': 'argument_list', 'children': ['95', '102']},{'id': '95', 'type': 'call', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'constant_database'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '104', 'type': 'lambda', 'children': ['105', '107']},{'id': '105', 'type': 'lambda_parameters', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '111', 'type': 'integer', 'children': [], 'value': '0'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '113', 'type': 'argument_list', 'children': []},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'SetConstantRecord'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125', '126']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '128', 'type': 'integer', 'children': [], 'value': '8'},{'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': 'records'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'PersistGraphRecord'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'address'},{'id': '140', 'type': 'integer', 'children': [], 'value': '8'},{'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': 'records'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'ClearConfigVariablesRecord'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'for_statement', 'children': ['151', '152', '168']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'slot'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '154', 'type': 'argument_list', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'config_database'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'key'},{'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', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '167', 'type': 'argument_list', 'children': []},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '179']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'config_id'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'subscript', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'config_database'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'slot'},{'id': '179', 'type': 'block', 'children': ['180', '192', '200']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '185']},{'id': '182', 'type': 'pattern_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'config_type'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '185', 'type': 'subscript', 'children': ['186', '191']},{'id': '186', 'type': 'subscript', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'sensor_graph'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'config_database'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'slot'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'config_id'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'byte_value'},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': '_convert_to_bytes'},{'id': '197', 'type': 'argument_list', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'config_type'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'value'},{'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': 'records'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'SetConfigRecord'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210', '211']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'slot'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'config_id'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'byte_value'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'app_tag'},{'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': 'sensor_graph'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'metadata_database'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'string', 'children': [], 'value': "'app_tag'"},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'app_version'},{'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': 'sensor_graph'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'metadata_database'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'string', 'children': [], 'value': "'app_version'"},{'id': '234', 'type': 'if_statement', 'children': ['235', '238']},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '237'], 'value': 'is'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'app_tag'},{'id': '237', 'type': 'None', 'children': []},{'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': 'records'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'SetDeviceTagRecord'},{'id': '247', 'type': 'argument_list', 'children': ['248', '251']},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'app_tag'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'app_tag'},{'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'app_version'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'app_version'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'script'},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'UpdateScript'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '261', 'type': 'return_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'script'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '266', 'type': 'argument_list', 'children': []}
def format_script(sensor_graph): records = [] records.append(SetGraphOnlineRecord(False, address=8)) records.append(ClearDataRecord(address=8)) records.append(ResetGraphRecord(address=8)) for node in sensor_graph.nodes: records.append(AddNodeRecord(str(node), address=8)) for streamer in sensor_graph.streamers: records.append(AddStreamerRecord(streamer, address=8)) for stream, value in sorted(sensor_graph.constant_database.items(), key=lambda x: x[0].encode()): records.append(SetConstantRecord(stream, value, address=8)) records.append(PersistGraphRecord(address=8)) records.append(ClearConfigVariablesRecord()) for slot in sorted(sensor_graph.config_database, key=lambda x: x.encode()): for config_id in sorted(sensor_graph.config_database[slot]): config_type, value = sensor_graph.config_database[slot][config_id] byte_value = _convert_to_bytes(config_type, value) records.append(SetConfigRecord(slot, config_id, byte_value)) app_tag = sensor_graph.metadata_database.get('app_tag') app_version = sensor_graph.metadata_database.get('app_version') if app_tag is not None: records.append(SetDeviceTagRecord(app_tag=app_tag, app_version=app_version)) script = UpdateScript(records) return script.encode()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'push'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '7', 'type': 'block', 'children': ['8', '17', '27', '134', '166', '188']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'reading'},{'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': 'reading'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'if_statement', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'buffered'},{'id': '31', 'type': 'block', 'children': ['32', '38', '57', '112']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'output_buffer'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '38', 'type': 'if_statement', 'children': ['39', '44']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': 'is'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'id_assigner'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'block', 'children': ['45']},{'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': 'reading'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'reading_id'},{'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': 'id_assigner'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '57', 'type': 'try_statement', 'children': ['58', '68']},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '66']},{'id': '61', 'type': 'attribute', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_engine'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'push'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '68', 'type': 'except_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'StorageFullError'},{'id': '70', 'type': 'block', 'children': ['71', '94', '103']},{'id': '71', 'type': 'if_statement', 'children': ['72', '92']},{'id': '72', 'type': 'boolean_operator', 'children': ['73', '82'], 'value': 'or'},{'id': '73', 'type': '()', 'children': ['74']},{'id': '74', 'type': 'boolean_operator', 'children': ['75', '78'], 'value': 'and'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '78', 'type': 'not_operator', 'children': ['79']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_rollover_streaming'},{'id': '82', 'type': '()', 'children': ['83']},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '88'], 'value': 'and'},{'id': '84', 'type': 'not_operator', 'children': ['85']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '88', 'type': 'not_operator', 'children': ['89']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': '_rollover_storage'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'raise_statement', 'children': []},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_erase_buffer'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'output'},{'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': '_engine'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'push'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '112', 'type': 'for_statement', 'children': ['113', '114', '117']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'walker'},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': '_queue_walkers'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'if_statement', 'children': ['119', '126']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '125'], 'value': '=='},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'walker'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'output_buffer'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'walker'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'notify_added'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '134', 'type': 'for_statement', 'children': ['135', '136', '139']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_monitors'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'if_statement', 'children': ['141', '151']},{'id': '141', 'type': 'boolean_operator', 'children': ['142', '145'], 'value': 'or'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'is'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '144', 'type': 'None', 'children': []},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'for_statement', 'children': ['153', '154', '159']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'callback'},{'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': '_monitors'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '166', 'type': 'for_statement', 'children': ['167', '168', '171']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'walker'},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': '_virtual_walkers'},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'if_statement', 'children': ['173', '179']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'walker'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'walker'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'push'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'reading'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '195']},{'id': '190', 'type': 'subscript', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': '_last_values'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'reading'}
def push(self, stream, reading): reading = copy.copy(reading) reading.stream = stream.encode() if stream.buffered: output_buffer = stream.output if self.id_assigner is not None: reading.reading_id = self.id_assigner(stream, reading) try: self._engine.push(reading) except StorageFullError: if (stream.output and not self._rollover_streaming) or (not stream.output and not self._rollover_storage): raise self._erase_buffer(stream.output) self._engine.push(reading) for walker in self._queue_walkers: if walker.selector.output == output_buffer: walker.notify_added(stream) for selector in self._monitors: if selector is None or selector.matches(stream): for callback in self._monitors[selector]: callback(stream, reading) for walker in self._virtual_walkers: if walker.matches(stream): walker.push(stream, reading) self._last_values[stream] = reading
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'inspect_last'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'only_allocated'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '48', '61']},{'id': '10', 'type': 'if_statement', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'only_allocated'},{'id': '12', 'type': 'block', 'children': ['13', '17', '36']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'for_statement', 'children': ['18', '19', '22']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'walker'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_virtual_walkers'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'if_statement', 'children': ['24', '30']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'walker'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '30', 'type': 'block', 'children': ['31', '35']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '34', 'type': 'True', 'children': []},{'id': '35', 'type': 'break_statement', 'children': []},{'id': '36', 'type': 'if_statement', 'children': ['37', '39']},{'id': '37', 'type': 'not_operator', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'raise_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'UnresolvedIdentifierError'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': '"inspect_last could not find an allocated virtual streamer for the desired stream"'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '48', 'type': 'if_statement', 'children': ['49', '54']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_last_values'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'subscript', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_last_values'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '61', 'type': 'raise_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'StreamEmptyError'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': 'u"inspect_last called on stream that has never been written to"'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'stream'}
def inspect_last(self, stream, only_allocated=False): if only_allocated: found = False for walker in self._virtual_walkers: if walker.matches(stream): found = True break if not found: raise UnresolvedIdentifierError("inspect_last could not find an allocated virtual streamer for the desired stream", stream=stream) if stream in self._last_values: return self._last_values[stream] raise StreamEmptyError(u"inspect_last called on stream that has never been written to", stream=stream)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_dllEmitter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '8', 'type': 'block', 'children': ['9', '20', '24', '28', '43', '53', '75', '84', '124', '145', '188', '231', '276', '331']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '18']},{'id': '11', 'type': 'attribute', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'Tool'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'msvc'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'validate_vars'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'extratargets'},{'id': '23', 'type': 'list', 'children': [], 'value': '[]'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'extrasources'},{'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': 'dll'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'FindIxes'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '40']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '%'},{'id': '38', 'type': 'string', 'children': [], 'value': "'%sPREFIX'"},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '%'},{'id': '41', 'type': 'string', 'children': [], 'value': "'%sSUFFIX'"},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'no_import_lib'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': "'no_import_lib'"},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'id': '53', 'type': 'if_statement', 'children': ['54', '56']},{'id': '54', 'type': 'not_operator', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'dll'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'raise_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': 'SCons'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'Errors'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'UserError'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '%'},{'id': '66', 'type': 'string', 'children': [], 'value': "'A shared library should have exactly one target with the suffix: %s'"},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '%'},{'id': '73', 'type': 'string', 'children': [], 'value': "'$%sSUFFIX'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'insert_def'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'string', 'children': [], 'value': '"$WINDOWS_INSERT_DEF"'},{'id': '84', 'type': 'if_statement', 'children': ['85', '103']},{'id': '85', 'type': 'boolean_operator', 'children': ['86', '93', '94'], 'value': 'and'},{'id': '86', 'type': 'not_operator', 'children': ['87']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'in'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'insert_def'},{'id': '89', 'type': 'list', 'children': ['90', '91', '92'], 'value': "['', '0', 0]"},{'id': '90', 'type': 'string', 'children': [], 'value': "''"},{'id': '91', 'type': 'string', 'children': [], 'value': "'0'"},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '94', 'type': 'not_operator', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'FindIxes'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101', '102']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '101', 'type': 'string', 'children': [], 'value': '"WINDOWSDEFPREFIX"'},{'id': '102', 'type': 'string', 'children': [], 'value': '"WINDOWSDEFSUFFIX"'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'extrasources'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'ReplaceIxes'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116', '119', '122', '123']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'dll'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '%'},{'id': '117', 'type': 'string', 'children': [], 'value': "'%sPREFIX'"},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '%'},{'id': '120', 'type': 'string', 'children': [], 'value': "'%sSUFFIX'"},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '122', 'type': 'string', 'children': [], 'value': '"WINDOWSDEFPREFIX"'},{'id': '123', 'type': 'string', 'children': [], 'value': '"WINDOWSDEFSUFFIX"'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '129']},{'id': '126', 'type': 'pattern_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'version_num'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'suite'},{'id': '129', 'type': 'call', 'children': ['130', '137']},{'id': '130', 'type': 'attribute', 'children': ['131', '136']},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Tool'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'msvs'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'msvs_parse_version'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': "'MSVS_VERSION'"},{'id': '144', 'type': 'string', 'children': [], 'value': "'6.0'"},{'id': '145', 'type': 'if_statement', 'children': ['146', '167']},{'id': '146', 'type': 'boolean_operator', 'children': ['147', '150', '151'], 'value': 'and'},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': '>='},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'version_num'},{'id': '149', 'type': 'float', 'children': [], 'value': '8.0'},{'id': '150', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '151', 'type': '()', 'children': ['152']},{'id': '152', 'type': 'boolean_operator', 'children': ['153', '160'], 'value': 'or'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159']},{'id': '158', 'type': 'string', 'children': [], 'value': "'WINDOWS_INSERT_MANIFEST'"},{'id': '159', 'type': 'integer', 'children': [], 'value': '0'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166']},{'id': '165', 'type': 'string', 'children': [], 'value': "'WINDOWS_EMBED_MANIFEST'"},{'id': '166', 'type': 'integer', 'children': [], 'value': '0'},{'id': '167', 'type': 'block', 'children': ['168']},{'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': 'extratargets'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'append'},{'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': 'env'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'ReplaceIxes'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180', '183', '186', '187']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'dll'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '%'},{'id': '181', 'type': 'string', 'children': [], 'value': "'%sPREFIX'"},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '%'},{'id': '184', 'type': 'string', 'children': [], 'value': "'%sSUFFIX'"},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '186', 'type': 'string', 'children': [], 'value': '"WINDOWSSHLIBMANIFESTPREFIX"'},{'id': '187', 'type': 'string', 'children': [], 'value': '"WINDOWSSHLIBMANIFESTSUFFIX"'},{'id': '188', 'type': 'if_statement', 'children': ['189', '196']},{'id': '189', 'type': 'boolean_operator', 'children': ['190', '193'], 'value': 'and'},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'in'},{'id': '191', 'type': 'string', 'children': [], 'value': "'PDB'"},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '195', 'type': 'string', 'children': [], 'value': "'PDB'"},{'id': '196', 'type': 'block', 'children': ['197', '214', '221']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '200', 'type': 'subscript', 'children': ['201', '213']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'arg2nodes'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207', '210']},{'id': '206', 'type': 'string', 'children': [], 'value': "'$PDB'"},{'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '213', 'type': 'integer', 'children': [], 'value': '0'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'extratargets'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '230']},{'id': '223', 'type': 'attribute', 'children': ['224', '229']},{'id': '224', 'type': 'attribute', 'children': ['225', '228']},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '227', 'type': 'integer', 'children': [], 'value': '0'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '231', 'type': 'if_statement', 'children': ['232', '243']},{'id': '232', 'type': 'boolean_operator', 'children': ['233', '236'], 'value': 'and'},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': '>='},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'version_num'},{'id': '235', 'type': 'float', 'children': [], 'value': '11.0'},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '240', 'type': 'argument_list', 'children': ['241', '242']},{'id': '241', 'type': 'string', 'children': [], 'value': "'PCH'"},{'id': '242', 'type': 'integer', 'children': [], 'value': '0'},{'id': '243', 'type': 'block', 'children': ['244', '264']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'pchobj'},{'id': '247', 'type': 'binary_operator', 'children': ['248', '263'], 'value': '+'},{'id': '248', 'type': 'subscript', 'children': ['249', '262']},{'id': '249', 'type': 'call', 'children': ['250', '255']},{'id': '250', 'type': 'attribute', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'SCons'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'Util'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'subscript', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '261', 'type': 'string', 'children': [], 'value': "'PCH'"},{'id': '262', 'type': 'integer', 'children': [], 'value': '0'},{'id': '263', 'type': 'string', 'children': [], 'value': "'.obj'"},{'id': '264', 'type': 'if_statement', 'children': ['265', '268']},{'id': '265', 'type': 'comparison_operator', 'children': ['266', '267'], 'value': 'not'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'pchobj'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'extrasources'},{'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': 'extrasources'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'pchobj'},{'id': '276', 'type': 'if_statement', 'children': ['277', '290']},{'id': '277', 'type': 'boolean_operator', 'children': ['278', '280', '281'], 'value': 'and'},{'id': '278', 'type': 'not_operator', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'no_import_lib'},{'id': '280', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '281', 'type': 'not_operator', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'FindIxes'},{'id': '286', 'type': 'argument_list', 'children': ['287', '288', '289']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '288', 'type': 'string', 'children': [], 'value': '"LIBPREFIX"'},{'id': '289', 'type': 'string', 'children': [], 'value': '"LIBSUFFIX"'},{'id': '290', 'type': 'block', 'children': ['291', '311']},{'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': 'extratargets'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'ReplaceIxes'},{'id': '301', 'type': 'argument_list', 'children': ['302', '303', '306', '309', '310']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'dll'},{'id': '303', 'type': 'binary_operator', 'children': ['304', '305'], 'value': '%'},{'id': '304', 'type': 'string', 'children': [], 'value': "'%sPREFIX'"},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '306', 'type': 'binary_operator', 'children': ['307', '308'], 'value': '%'},{'id': '307', 'type': 'string', 'children': [], 'value': "'%sSUFFIX'"},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '309', 'type': 'string', 'children': [], 'value': '"LIBPREFIX"'},{'id': '310', 'type': 'string', 'children': [], 'value': '"LIBSUFFIX"'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'extratargets'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'ReplaceIxes'},{'id': '321', 'type': 'argument_list', 'children': ['322', '323', '326', '329', '330']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'dll'},{'id': '323', 'type': 'binary_operator', 'children': ['324', '325'], 'value': '%'},{'id': '324', 'type': 'string', 'children': [], 'value': "'%sPREFIX'"},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '326', 'type': 'binary_operator', 'children': ['327', '328'], 'value': '%'},{'id': '327', 'type': 'string', 'children': [], 'value': "'%sSUFFIX'"},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'paramtp'},{'id': '329', 'type': 'string', 'children': [], 'value': '"WINDOWSEXPPREFIX"'},{'id': '330', 'type': 'string', 'children': [], 'value': '"WINDOWSEXPSUFFIX"'},{'id': '331', 'type': 'return_statement', 'children': ['332']},{'id': '332', 'type': 'tuple', 'children': ['333', '336']},{'id': '333', 'type': 'binary_operator', 'children': ['334', '335'], 'value': '+'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'extratargets'},{'id': '336', 'type': 'binary_operator', 'children': ['337', '338'], 'value': '+'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'extrasources'}
def _dllEmitter(target, source, env, paramtp): SCons.Tool.msvc.validate_vars(env) extratargets = [] extrasources = [] dll = env.FindIxes(target, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp) no_import_lib = env.get('no_import_lib', 0) if not dll: raise SCons.Errors.UserError('A shared library should have exactly one target with the suffix: %s' % env.subst('$%sSUFFIX' % paramtp)) insert_def = env.subst("$WINDOWS_INSERT_DEF") if not insert_def in ['', '0', 0] and \ not env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"): extrasources.append( env.ReplaceIxes(dll, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX")) version_num, suite = SCons.Tool.msvs.msvs_parse_version(env.get('MSVS_VERSION', '6.0')) if version_num >= 8.0 and \ (env.get('WINDOWS_INSERT_MANIFEST', 0) or env.get('WINDOWS_EMBED_MANIFEST', 0)): extratargets.append( env.ReplaceIxes(dll, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "WINDOWSSHLIBMANIFESTPREFIX", "WINDOWSSHLIBMANIFESTSUFFIX")) if 'PDB' in env and env['PDB']: pdb = env.arg2nodes('$PDB', target=target, source=source)[0] extratargets.append(pdb) target[0].attributes.pdb = pdb if version_num >= 11.0 and env.get('PCH', 0): pchobj = SCons.Util.splitext(str(env['PCH']))[0] + '.obj' if pchobj not in extrasources: extrasources.append(pchobj) if not no_import_lib and \ not env.FindIxes(target, "LIBPREFIX", "LIBSUFFIX"): extratargets.append( env.ReplaceIxes(dll, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "LIBPREFIX", "LIBSUFFIX")) extratargets.append( env.ReplaceIxes(dll, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "WINDOWSEXPPREFIX", "WINDOWSEXPSUFFIX")) return (target+extratargets, source+extrasources)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup_environment'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'chip'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args_file'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '15', '56', '62', '68', '74', '80', '90', '96', '102', '108', '114', '120', '126', '132', '165', '176', '187', '201', '215', '230', '236', '252', '268', '284', '300', '306', '312']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ConfigManager'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'if_statement', 'children': ['16', '23', '39']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '22'], 'value': '=='},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'string', 'children': [], 'value': "'Windows'"},{'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': 'env'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'Environment'},{'id': '29', 'type': 'argument_list', 'children': ['30', '34']},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'tools'},{'id': '32', 'type': 'list', 'children': ['33'], 'value': "['mingw']"},{'id': '33', 'type': 'string', 'children': [], 'value': "'mingw'"},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ENV'},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '39', 'type': 'else_clause', 'children': ['40']},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'Environment'},{'id': '46', 'type': 'argument_list', 'children': ['47', '51']},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'tools'},{'id': '49', 'type': 'list', 'children': ['50'], 'value': "['default']"},{'id': '50', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ENV'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '61']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '60', 'type': 'string', 'children': [], 'value': "'INCPREFIX'"},{'id': '61', 'type': 'string', 'children': [], 'value': '\'-I"\''},{'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': 'env'},{'id': '66', 'type': 'string', 'children': [], 'value': "'INCSUFFIX'"},{'id': '67', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '72', 'type': 'string', 'children': [], 'value': "'CPPDEFPREFIX'"},{'id': '73', 'type': 'string', 'children': [], 'value': "''"},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '78', 'type': 'string', 'children': [], 'value': "'CPPDEFSUFFIX'"},{'id': '79', 'type': 'string', 'children': [], 'value': "''"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '84', 'type': 'string', 'children': [], 'value': "'CPPPATH'"},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'chip'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'includes'},{'id': '89', 'type': 'argument_list', 'children': []},{'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': 'env'},{'id': '94', 'type': 'string', 'children': [], 'value': "'ARCH'"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'chip'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '100', 'type': 'string', 'children': [], 'value': "'CC'"},{'id': '101', 'type': 'string', 'children': [], 'value': "'arm-none-eabi-gcc'"},{'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': 'env'},{'id': '106', 'type': 'string', 'children': [], 'value': "'AS'"},{'id': '107', 'type': 'string', 'children': [], 'value': "'arm-none-eabi-gcc'"},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '112', 'type': 'string', 'children': [], 'value': "'LINK'"},{'id': '113', 'type': 'string', 'children': [], 'value': "'arm-none-eabi-gcc'"},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '119']},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '118', 'type': 'string', 'children': [], 'value': "'AR'"},{'id': '119', 'type': 'string', 'children': [], 'value': "'arm-none-eabi-ar'"},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '125']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '124', 'type': 'string', 'children': [], 'value': "'RANLIB'"},{'id': '125', 'type': 'string', 'children': [], 'value': "'arm-none-eabi-ranlib'"},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '130', 'type': 'string', 'children': [], 'value': "'ASCOM'"},{'id': '131', 'type': 'string', 'children': [], 'value': '"$AS $ASFLAGS -o $TARGET -c $SOURCES"'},{'id': '132', 'type': 'if_statement', 'children': ['133', '140']},{'id': '133', 'type': 'not_operator', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'string', 'children': [], 'value': "'build:show-commands'"},{'id': '140', 'type': 'block', 'children': ['141', '147', '153', '159']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '146']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '145', 'type': 'string', 'children': [], 'value': "'CCCOMSTR'"},{'id': '146', 'type': 'string', 'children': [], 'value': '"Compiling $TARGET"'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '151', 'type': 'string', 'children': [], 'value': "'ARCOMSTR'"},{'id': '152', 'type': 'string', 'children': [], 'value': '"Building static library $TARGET"'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '158']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '157', 'type': 'string', 'children': [], 'value': "'RANLIBCOMSTR'"},{'id': '158', 'type': 'string', 'children': [], 'value': '"Indexing static library $TARGET"'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '164']},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '163', 'type': 'string', 'children': [], 'value': "'LINKCOMSTR'"},{'id': '164', 'type': 'string', 'children': [], 'value': '"Linking $TARGET"'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '170']},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '169', 'type': 'string', 'children': [], 'value': "'CCFLAGS'"},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'chip'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'combined_properties'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'string', 'children': [], 'value': "'cflags'"},{'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': 'env'},{'id': '180', 'type': 'string', 'children': [], 'value': "'LINKFLAGS'"},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'chip'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'combined_properties'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'string', 'children': [], 'value': "'ldflags'"},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '194']},{'id': '189', 'type': 'attribute', 'children': ['190', '193']},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '192', 'type': 'string', 'children': [], 'value': "'ARFLAGS'"},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'chip'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'combined_properties'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'string', 'children': [], 'value': "'arflags'"},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '208']},{'id': '203', 'type': 'attribute', 'children': ['204', '207']},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '206', 'type': 'string', 'children': [], 'value': "'ASFLAGS'"},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'chip'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'combined_properties'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'string', 'children': [], 'value': "'asflags'"},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'defines'},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'utilities'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'build_defines'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'chip'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229']},{'id': '228', 'type': 'string', 'children': [], 'value': "'defines'"},{'id': '229', 'type': 'dictionary', 'children': []},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '235']},{'id': '232', 'type': 'subscript', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '234', 'type': 'string', 'children': [], 'value': "'CPPDEFINES'"},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'defines'},{'id': '236', 'type': 'if_statement', 'children': ['237', '240']},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': 'is'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'args_file'},{'id': '239', 'type': 'None', 'children': []},{'id': '240', 'type': 'block', 'children': ['241']},{'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': 'env'},{'id': '245', 'type': 'string', 'children': [], 'value': "'CCCOM'"},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'string', 'children': [], 'value': '"$CC $CCFLAGS $CPPFLAGS @{} -c -o $TARGET $SOURCES"'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'args_file'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '259']},{'id': '254', 'type': 'attribute', 'children': ['255', '258']},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '257', 'type': 'string', 'children': [], 'value': "'CCFLAGS'"},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'binary_operator', 'children': ['261', '262'], 'value': '%'},{'id': '261', 'type': 'string', 'children': [], 'value': "'-mcpu=%s'"},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'chip'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'string', 'children': [], 'value': "'cpu'"},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '275']},{'id': '270', 'type': 'attribute', 'children': ['271', '274']},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '273', 'type': 'string', 'children': [], 'value': "'ASFLAGS'"},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'binary_operator', 'children': ['277', '278'], 'value': '%'},{'id': '277', 'type': 'string', 'children': [], 'value': "'-mcpu=%s'"},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'chip'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'string', 'children': [], 'value': "'cpu'"},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'call', 'children': ['286', '291']},{'id': '286', 'type': 'attribute', 'children': ['287', '290']},{'id': '287', 'type': 'subscript', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '289', 'type': 'string', 'children': [], 'value': "'LINKFLAGS'"},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'binary_operator', 'children': ['293', '294'], 'value': '%'},{'id': '293', 'type': 'string', 'children': [], 'value': "'-mcpu=%s'"},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'chip'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'string', 'children': [], 'value': "'cpu'"},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '305']},{'id': '302', 'type': 'subscript', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '304', 'type': 'string', 'children': [], 'value': "'LIBPATH'"},{'id': '305', 'type': 'list', 'children': [], 'value': '[]'},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '311']},{'id': '308', 'type': 'subscript', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '310', 'type': 'string', 'children': [], 'value': "'LIBS'"},{'id': '311', 'type': 'list', 'children': [], 'value': '[]'},{'id': '312', 'type': 'return_statement', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'env'}
def setup_environment(chip, args_file=None): config = ConfigManager() if platform.system() == 'Windows': env = Environment(tools=['mingw'], ENV=os.environ) else: env = Environment(tools=['default'], ENV=os.environ) env['INCPREFIX'] = '-I"' env['INCSUFFIX'] = '"' env['CPPDEFPREFIX'] = '' env['CPPDEFSUFFIX'] = '' env['CPPPATH'] = chip.includes() env['ARCH'] = chip env['CC'] = 'arm-none-eabi-gcc' env['AS'] = 'arm-none-eabi-gcc' env['LINK'] = 'arm-none-eabi-gcc' env['AR'] = 'arm-none-eabi-ar' env['RANLIB'] = 'arm-none-eabi-ranlib' env['ASCOM'] = "$AS $ASFLAGS -o $TARGET -c $SOURCES" if not config.get('build:show-commands'): env['CCCOMSTR'] = "Compiling $TARGET" env['ARCOMSTR'] = "Building static library $TARGET" env['RANLIBCOMSTR'] = "Indexing static library $TARGET" env['LINKCOMSTR'] = "Linking $TARGET" env['CCFLAGS'] = chip.combined_properties('cflags') env['LINKFLAGS'] = chip.combined_properties('ldflags') env['ARFLAGS'].append(chip.combined_properties('arflags')) env['ASFLAGS'].append(chip.combined_properties('asflags')) defines = utilities.build_defines(chip.property('defines', {})) env['CPPDEFINES'] = defines if args_file is not None: env['CCCOM'] = "$CC $CCFLAGS $CPPFLAGS @{} -c -o $TARGET $SOURCES".format(args_file) env['CCFLAGS'].append('-mcpu=%s' % chip.property('cpu')) env['ASFLAGS'].append('-mcpu=%s' % chip.property('cpu')) env['LINKFLAGS'].append('-mcpu=%s' % chip.property('cpu')) env['LIBPATH'] = [] env['LIBS'] = [] return env
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fastqRead'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fileHandleOrFile'},{'id': '5', 'type': 'block', 'children': ['6', '13', '21', '208']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'fileHandle'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_getFileHandle'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'fileHandleOrFile'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'fileHandle'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'while_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': '!='},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '24', 'type': 'string', 'children': [], 'value': "''"},{'id': '25', 'type': 'block', 'children': ['26', '200']},{'id': '26', 'type': 'if_statement', 'children': ['27', '32']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': '=='},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '32', 'type': 'block', 'children': ['33', '43', '56', '64', '78', '98', '153', '194']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '38', 'type': 'slice', 'children': ['39', '40', '41']},{'id': '39', 'type': 'integer', 'children': [], 'value': '1'},{'id': '40', 'type': 'colon', 'children': []},{'id': '41', 'type': 'unary_operator', 'children': ['42'], 'value': '-'},{'id': '42', 'type': 'integer', 'children': [], 'value': '1'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '46', 'type': 'subscript', 'children': ['47', '52']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'fileHandle'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'slice', 'children': ['53', '54']},{'id': '53', 'type': 'colon', 'children': []},{'id': '54', 'type': 'unary_operator', 'children': ['55'], 'value': '-'},{'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': 'plus'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'fileHandle'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'if_statement', 'children': ['65', '70']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': '!='},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'plus'},{'id': '68', 'type': 'integer', 'children': [], 'value': '0'},{'id': '69', 'type': 'string', 'children': [], 'value': "'+'"},{'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': 'RuntimeError'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '%'},{'id': '76', 'type': 'string', 'children': [], 'value': '"Got unexpected line: %s"'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'plus'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'qualValues'},{'id': '81', 'type': 'list_comprehension', 'children': ['82', '86']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ord'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '86', 'type': 'for_in_clause', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '88', 'type': 'subscript', 'children': ['89', '94']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'fileHandle'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '93', 'type': 'argument_list', 'children': []},{'id': '94', 'type': 'slice', 'children': ['95', '96']},{'id': '95', 'type': 'colon', 'children': []},{'id': '96', 'type': 'unary_operator', 'children': ['97'], 'value': '-'},{'id': '97', 'type': 'integer', 'children': [], 'value': '1'},{'id': '98', 'type': 'if_statement', 'children': ['99', '108', '131']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '104'], 'value': '!='},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'seq'},{'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': 'qualValues'},{'id': '108', 'type': 'block', 'children': ['109', '127']},{'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': 'logger'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'critical'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '%'},{'id': '116', 'type': 'string', 'children': [], 'value': '"Got a mismatch between the number of sequence characters (%s) and number of qual values (%s) for sequence: %s, ignoring returning None"'},{'id': '117', 'type': 'tuple', 'children': ['118', '122', '126']},{'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': 'seq'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'qualValues'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'qualValues'},{'id': '130', 'type': 'None', 'children': []},{'id': '131', 'type': 'else_clause', 'children': ['132']},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'for_statement', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'qualValues'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'if_statement', 'children': ['138', '145']},{'id': '138', 'type': 'boolean_operator', 'children': ['139', '142'], 'value': 'or'},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '<'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '141', 'type': 'integer', 'children': [], 'value': '33'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '>'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '144', 'type': 'integer', 'children': [], 'value': '126'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'raise_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '%'},{'id': '151', 'type': 'string', 'children': [], 'value': '"Got a qual value out of range %s (range is 33 to 126)"'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '153', 'type': 'for_statement', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'if_statement', 'children': ['158', '181']},{'id': '158', 'type': 'not_operator', 'children': ['159']},{'id': '159', 'type': '()', 'children': ['160']},{'id': '160', 'type': 'boolean_operator', 'children': ['161', '178'], 'value': 'or'},{'id': '161', 'type': 'boolean_operator', 'children': ['162', '170'], 'value': 'or'},{'id': '162', 'type': '()', 'children': ['163']},{'id': '163', 'type': 'boolean_operator', 'children': ['164', '167'], 'value': 'and'},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': '>='},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '166', 'type': 'string', 'children': [], 'value': "'A'"},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': '<='},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '169', 'type': 'string', 'children': [], 'value': "'Z'"},{'id': '170', 'type': '()', 'children': ['171']},{'id': '171', 'type': 'boolean_operator', 'children': ['172', '175'], 'value': 'and'},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': '>='},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '174', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '<='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '177', 'type': 'string', 'children': [], 'value': "'z'"},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': '=='},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '180', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'raise_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '%'},{'id': '187', 'type': 'string', 'children': [], 'value': '"Invalid FASTQ character, ASCII code = \\\'%d\\\', found in input sequence %s"'},{'id': '188', 'type': 'tuple', 'children': ['189', '193']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'ord'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'yield', 'children': ['196']},{'id': '196', 'type': 'expression_list', 'children': ['197', '198', '199']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'qualValues'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'fileHandle'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'if_statement', 'children': ['209', '216']},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'fileHandleOrFile'},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'string', 'children': [], 'value': '""'},{'id': '215', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'fileHandle'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '222', 'type': 'argument_list', 'children': []}
def fastqRead(fileHandleOrFile): fileHandle = _getFileHandle(fileHandleOrFile) line = fileHandle.readline() while line != '': if line[0] == '@': name = line[1:-1] seq = fileHandle.readline()[:-1] plus = fileHandle.readline() if plus[0] != '+': raise RuntimeError("Got unexpected line: %s" % plus) qualValues = [ ord(i) for i in fileHandle.readline()[:-1] ] if len(seq) != len(qualValues): logger.critical("Got a mismatch between the number of sequence characters (%s) and number of qual values (%s) for sequence: %s, ignoring returning None" % (len(seq), len(qualValues), name)) qualValues = None else: for i in qualValues: if i < 33 or i > 126: raise RuntimeError("Got a qual value out of range %s (range is 33 to 126)" % i) for i in seq: if not ((i >= 'A' and i <= 'Z') or (i >= 'a' and i <= 'z') or i == '-'): raise RuntimeError("Invalid FASTQ character, ASCII code = \'%d\', found in input sequence %s" % (ord(i), name)) yield name, seq, qualValues line = fileHandle.readline() if isinstance(fileHandleOrFile, "".__class__): fileHandle.close()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'newickTreeParser'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'defaultDistance'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_DISTANCE'},{'id': '8', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sortNonBinaryNodes'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'reportUnaryNodes'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '26', '36', '46', '56', '66', '80', '92', '140', '187', '426']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': '"("'},{'id': '25', 'type': 'string', 'children': [], 'value': '" ( "'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': '")"'},{'id': '35', 'type': 'string', 'children': [], 'value': '" ) "'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': '":"'},{'id': '45', 'type': 'string', 'children': [], 'value': '" : "'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'string', 'children': [], 'value': '";"'},{'id': '55', 'type': 'string', 'children': [], 'value': '""'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': '","'},{'id': '65', 'type': 'string', 'children': [], 'value': '" , "'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '69', 'type': 'call', 'children': ['70', '78']},{'id': '70', 'type': 'attribute', 'children': ['71', '77']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': '"[\\s]*"'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '80', 'type': 'while_statement', 'children': ['81', '84']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'in'},{'id': '82', 'type': 'string', 'children': [], 'value': '""'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': '""'},{'id': '92', 'type': 'function_definition', 'children': ['93', '94', '97']},{'id': '93', 'type': 'function_name', 'children': [], 'value': 'fn'},{'id': '94', 'type': 'parameters', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '97', 'type': 'block', 'children': ['98', '138']},{'id': '98', 'type': 'if_statement', 'children': ['99', '107']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': '<'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '102', 'type': 'integer', 'children': [], 'value': '0'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'if_statement', 'children': ['109', '116']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '115'], 'value': '=='},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '114', 'type': 'integer', 'children': [], 'value': '0'},{'id': '115', 'type': 'string', 'children': [], 'value': "':'"},{'id': '116', 'type': 'block', 'children': ['117', '130', '136']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '129'], 'value': '+'},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '128', 'type': 'integer', 'children': [], 'value': '0'},{'id': '129', 'type': 'integer', 'children': [], 'value': '1'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'augmented_assignment', 'children': ['132', '135'], 'value': '+='},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '134', 'type': 'integer', 'children': [], 'value': '0'},{'id': '135', 'type': 'integer', 'children': [], 'value': '2'},{'id': '136', 'type': 'return_statement', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'defaultDistance'},{'id': '140', 'type': 'function_definition', 'children': ['141', '142', '145']},{'id': '141', 'type': 'function_name', 'children': [], 'value': 'fn2'},{'id': '142', 'type': 'parameters', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '145', 'type': 'block', 'children': ['146', '185']},{'id': '146', 'type': 'if_statement', 'children': ['147', '155']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '151'], 'value': '<'},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '150', 'type': 'integer', 'children': [], 'value': '0'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '155', 'type': 'block', 'children': ['156', '164']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '163', 'type': 'integer', 'children': [], 'value': '0'},{'id': '164', 'type': 'if_statement', 'children': ['165', '176']},{'id': '165', 'type': 'boolean_operator', 'children': ['166', '173'], 'value': 'and'},{'id': '166', 'type': 'boolean_operator', 'children': ['167', '170'], 'value': 'and'},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': '!='},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '169', 'type': 'string', 'children': [], 'value': "':'"},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '!='},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '172', 'type': 'string', 'children': [], 'value': "')'"},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '!='},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '175', 'type': 'string', 'children': [], 'value': "','"},{'id': '176', 'type': 'block', 'children': ['177', '183']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'augmented_assignment', 'children': ['179', '182'], 'value': '+='},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '181', 'type': 'integer', 'children': [], 'value': '0'},{'id': '182', 'type': 'integer', 'children': [], 'value': '1'},{'id': '183', 'type': 'return_statement', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '185', 'type': 'return_statement', 'children': ['186']},{'id': '186', 'type': 'None', 'children': []},{'id': '187', 'type': 'function_definition', 'children': ['188', '189', '192']},{'id': '188', 'type': 'function_name', 'children': [], 'value': 'fn3'},{'id': '189', 'type': 'parameters', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '192', 'type': 'block', 'children': ['193', '405', '413']},{'id': '193', 'type': 'if_statement', 'children': ['194', '201']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '200'], 'value': '=='},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '199', 'type': 'integer', 'children': [], 'value': '0'},{'id': '200', 'type': 'string', 'children': [], 'value': "'('"},{'id': '201', 'type': 'block', 'children': ['202', '206', '212', '216', '251', '257', '288', '298', '304', '403']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'subTreeList'},{'id': '205', 'type': 'list', 'children': [], 'value': '[]'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'augmented_assignment', 'children': ['208', '211'], 'value': '+='},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '210', 'type': 'integer', 'children': [], 'value': '0'},{'id': '211', 'type': 'integer', 'children': [], 'value': '1'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '215', 'type': 'list', 'children': [], 'value': '[]'},{'id': '216', 'type': 'while_statement', 'children': ['217', '224']},{'id': '217', 'type': 'comparison_operator', 'children': ['218', '223'], 'value': '!='},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '220', 'type': 'subscript', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '222', 'type': 'integer', 'children': [], 'value': '0'},{'id': '223', 'type': 'string', 'children': [], 'value': "')'"},{'id': '224', 'type': 'block', 'children': ['225', '240']},{'id': '225', 'type': 'if_statement', 'children': ['226', '233']},{'id': '226', 'type': 'comparison_operator', 'children': ['227', '232'], 'value': '=='},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '231', 'type': 'integer', 'children': [], 'value': '0'},{'id': '232', 'type': 'string', 'children': [], 'value': "','"},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'augmented_assignment', 'children': ['236', '239'], 'value': '+='},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '238', 'type': 'integer', 'children': [], 'value': '0'},{'id': '239', 'type': 'integer', 'children': [], 'value': '1'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'subTreeList'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'fn3'},{'id': '248', 'type': 'argument_list', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'augmented_assignment', 'children': ['253', '256'], 'value': '+='},{'id': '253', 'type': 'subscript', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '255', 'type': 'integer', 'children': [], 'value': '0'},{'id': '256', 'type': 'integer', 'children': [], 'value': '1'},{'id': '257', 'type': 'function_definition', 'children': ['258', '259', '262']},{'id': '258', 'type': 'function_name', 'children': [], 'value': 'cmp'},{'id': '259', 'type': 'parameters', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '262', 'type': 'block', 'children': ['263', '275', '286']},{'id': '263', 'type': 'if_statement', 'children': ['264', '271']},{'id': '264', 'type': 'comparison_operator', 'children': ['265', '268'], 'value': '<'},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'return_statement', 'children': ['273']},{'id': '273', 'type': 'unary_operator', 'children': ['274'], 'value': '-'},{'id': '274', 'type': 'integer', 'children': [], 'value': '1'},{'id': '275', 'type': 'if_statement', 'children': ['276', '283']},{'id': '276', 'type': 'comparison_operator', 'children': ['277', '280'], 'value': '>'},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '283', 'type': 'block', 'children': ['284']},{'id': '284', 'type': 'return_statement', 'children': ['285']},{'id': '285', 'type': 'integer', 'children': [], 'value': '1'},{'id': '286', 'type': 'return_statement', 'children': ['287']},{'id': '287', 'type': 'integer', 'children': [], 'value': '0'},{'id': '288', 'type': 'if_statement', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'sortNonBinaryNodes'},{'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': 'subTreeList'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'subTree1'},{'id': '301', 'type': 'subscript', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'subTreeList'},{'id': '303', 'type': 'integer', 'children': [], 'value': '0'},{'id': '304', 'type': 'if_statement', 'children': ['305', '311', '351', '385']},{'id': '305', 'type': 'comparison_operator', 'children': ['306', '310'], 'value': '>'},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'subTreeList'},{'id': '310', 'type': 'integer', 'children': [], 'value': '1'},{'id': '311', 'type': 'block', 'children': ['312', '331', '341']},{'id': '312', 'type': 'for_statement', 'children': ['313', '314', '319']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'subTree2'},{'id': '314', 'type': 'subscript', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'subTreeList'},{'id': '316', 'type': 'slice', 'children': ['317', '318']},{'id': '317', 'type': 'integer', 'children': [], 'value': '1'},{'id': '318', 'type': 'colon', 'children': []},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'assignment', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'subTree1'},{'id': '323', 'type': 'call', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'BinaryTree'},{'id': '325', 'type': 'argument_list', 'children': ['326', '327', '328', '329', '330']},{'id': '326', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '327', 'type': 'True', 'children': []},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'subTree1'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'subTree2'},{'id': '330', 'type': 'None', 'children': []},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'assignment', 'children': ['333', '336']},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'subTree1'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'iD'},{'id': '336', 'type': 'call', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'fn2'},{'id': '338', 'type': 'argument_list', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'augmented_assignment', 'children': ['343', '346'], 'value': '+='},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'subTree1'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '346', 'type': 'call', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '348', 'type': 'argument_list', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '351', 'type': 'elif_clause', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'reportUnaryNodes'},{'id': '353', 'type': 'block', 'children': ['354', '365', '375']},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'assignment', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'subTree1'},{'id': '357', 'type': 'call', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'BinaryTree'},{'id': '359', 'type': 'argument_list', 'children': ['360', '361', '362', '363', '364']},{'id': '360', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '361', 'type': 'True', 'children': []},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'subTree1'},{'id': '363', 'type': 'None', 'children': []},{'id': '364', 'type': 'None', 'children': []},{'id': '365', 'type': 'expression_statement', 'children': ['366']},{'id': '366', 'type': 'assignment', 'children': ['367', '370']},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'subTree1'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'iD'},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'fn2'},{'id': '372', 'type': 'argument_list', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'augmented_assignment', 'children': ['377', '380'], 'value': '+='},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'subTree1'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '380', 'type': 'call', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '382', 'type': 'argument_list', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '385', 'type': 'else_clause', 'children': ['386']},{'id': '386', 'type': 'block', 'children': ['387', '393']},{'id': '387', 'type': 'expression_statement', 'children': ['388']},{'id': '388', 'type': 'call', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'fn2'},{'id': '390', 'type': 'argument_list', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'augmented_assignment', 'children': ['395', '398'], 'value': '+='},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'subTree1'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '398', 'type': 'call', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '400', 'type': 'argument_list', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '403', 'type': 'return_statement', 'children': ['404']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'subTree1'},{'id': '405', 'type': 'expression_statement', 'children': ['406']},{'id': '406', 'type': 'assignment', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'leafID'},{'id': '408', 'type': 'call', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'fn2'},{'id': '410', 'type': 'argument_list', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '413', 'type': 'return_statement', 'children': ['414']},{'id': '414', 'type': 'call', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'BinaryTree'},{'id': '416', 'type': 'argument_list', 'children': ['417', '422', '423', '424', '425']},{'id': '417', 'type': 'call', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '419', 'type': 'argument_list', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '422', 'type': 'False', 'children': []},{'id': '423', 'type': 'None', 'children': []},{'id': '424', 'type': 'None', 'children': []},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'leafID'},{'id': '426', 'type': 'return_statement', 'children': ['427']},{'id': '427', 'type': 'call', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'fn3'},{'id': '429', 'type': 'argument_list', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'newickTree'},{'id': '431', 'type': 'list', 'children': ['432'], 'value': '[0]'},{'id': '432', 'type': 'integer', 'children': [], 'value': '0'}
def newickTreeParser(newickTree, defaultDistance=DEFAULT_DISTANCE, \ sortNonBinaryNodes=False, reportUnaryNodes=False): newickTree = newickTree.replace("(", " ( ") newickTree = newickTree.replace(")", " ) ") newickTree = newickTree.replace(":", " : ") newickTree = newickTree.replace(";", "") newickTree = newickTree.replace(",", " , ") newickTree = re.compile("[\s]*").split(newickTree) while "" in newickTree: newickTree.remove("") def fn(newickTree, i): if i[0] < len(newickTree): if newickTree[i[0]] == ':': d = float(newickTree[i[0]+1]) i[0] += 2 return d return defaultDistance def fn2(newickTree, i): if i[0] < len(newickTree): j = newickTree[i[0]] if j != ':' and j != ')' and j != ',': i[0] += 1 return j return None def fn3(newickTree, i): if newickTree[i[0]] == '(': subTreeList = [] i[0] += 1 k = [] while newickTree[i[0]] != ')': if newickTree[i[0]] == ',': i[0] += 1 subTreeList.append(fn3(newickTree, i)) i[0] += 1 def cmp(i, j): if i.distance < j.distance: return -1 if i.distance > j.distance: return 1 return 0 if sortNonBinaryNodes: subTreeList.sort(cmp) subTree1 = subTreeList[0] if len(subTreeList) > 1: for subTree2 in subTreeList[1:]: subTree1 = BinaryTree(0.0, True, subTree1, subTree2, None) subTree1.iD = fn2(newickTree, i) subTree1.distance += fn(newickTree, i) elif reportUnaryNodes: subTree1 = BinaryTree(0.0, True, subTree1, None, None) subTree1.iD = fn2(newickTree, i) subTree1.distance += fn(newickTree, i) else: fn2(newickTree, i) subTree1.distance += fn(newickTree, i) return subTree1 leafID = fn2(newickTree, i) return BinaryTree(fn(newickTree, i), False, None, None, leafID) return fn3(newickTree, [0])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_iptables_rule'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '5', 'type': 'block', 'children': ['6', '8', '16', '20', '24', '28', '32', '90', '154', '161', '177']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Parse one iptables rule. Returns a dict where each iptables code argument\n is mapped to a name using IPTABLES_ARGS.\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'bits'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '19', 'type': 'dictionary', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'},{'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': 'not_arg'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'function_definition', 'children': ['33', '34', '35']},{'id': '33', 'type': 'function_name', 'children': [], 'value': 'add_args'},{'id': '34', 'type': 'parameters', 'children': []},{'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': 'arg_string'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "' '"},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '45', 'type': 'if_statement', 'children': ['46', '49', '73']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'in'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'IPTABLES_ARGS'},{'id': '49', 'type': 'block', 'children': ['50', '67']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'definition_key'},{'id': '53', 'type': '()', 'children': ['54']},{'id': '54', 'type': 'conditional_expression', 'children': ['55', '63', '64'], 'value': 'if'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "'not_{0}'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'IPTABLES_ARGS'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'not_arg'},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'IPTABLES_ARGS'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '72']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'definition_key'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'arg_string'},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '86']},{'id': '77', 'type': 'attribute', 'children': ['78', '85']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "'extras'"},{'id': '84', 'type': 'list', 'children': [], 'value': '[]'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'tuple', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'arg_string'},{'id': '90', 'type': 'for_statement', 'children': ['91', '92', '93']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'bits'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'if_statement', 'children': ['95', '98', '118', '145']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '=='},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '97', 'type': 'string', 'children': [], 'value': "'!'"},{'id': '98', 'type': 'block', 'children': ['99', '114']},{'id': '99', 'type': 'if_statement', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '101', 'type': 'block', 'children': ['102', '106', '110']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'add_args'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '109', 'type': 'list', 'children': [], 'value': '[]'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '113', 'type': 'None', 'children': []},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'not_arg'},{'id': '117', 'type': 'True', 'children': []},{'id': '118', 'type': 'elif_clause', 'children': ['119', '125']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '125', 'type': 'block', 'children': ['126', '141']},{'id': '126', 'type': 'if_statement', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '128', 'type': 'block', 'children': ['129', '133', '137']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'add_args'},{'id': '132', 'type': 'argument_list', 'children': []},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '136', 'type': 'list', 'children': [], 'value': '[]'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'not_arg'},{'id': '140', 'type': 'False', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '145', 'type': 'else_clause', 'children': ['146']},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '154', 'type': 'if_statement', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'add_args'},{'id': '160', 'type': 'argument_list', 'children': []},{'id': '161', 'type': 'if_statement', 'children': ['162', '165']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': 'in'},{'id': '163', 'type': 'string', 'children': [], 'value': "'extras'"},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '171']},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '170', 'type': 'string', 'children': [], 'value': "'extras'"},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '176', 'type': 'string', 'children': [], 'value': "'extras'"},{'id': '177', 'type': 'return_statement', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'definition'}
def parse_iptables_rule(line): ''' Parse one iptables rule. Returns a dict where each iptables code argument is mapped to a name using IPTABLES_ARGS. ''' bits = line.split() definition = {} key = None args = [] not_arg = False def add_args(): arg_string = ' '.join(args) if key in IPTABLES_ARGS: definition_key = ( 'not_{0}'.format(IPTABLES_ARGS[key]) if not_arg else IPTABLES_ARGS[key] ) definition[definition_key] = arg_string else: definition.setdefault('extras', []).extend((key, arg_string)) for bit in bits: if bit == '!': if key: add_args() args = [] key = None not_arg = True elif bit.startswith('-'): if key: add_args() args = [] not_arg = False key = bit else: args.append(bit) if key: add_args() if 'extras' in definition: definition['extras'] = set(definition['extras']) return definition
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_command'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'su_user'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sudo'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sudo_user'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'preserve_sudo_env'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '23', '27', '54', '88', '127', '134', '158', '204']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': "'''\n Builds a shell command with various kwargs.\n '''"},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'debug_meta'},{'id': '26', 'type': 'dictionary', 'children': []},{'id': '27', 'type': 'for_statement', 'children': ['28', '31', '44']},{'id': '28', 'type': 'pattern_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '31', 'type': 'tuple', 'children': ['32', '35', '38', '41']},{'id': '32', 'type': 'tuple', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'sudo'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sudo'},{'id': '35', 'type': 'tuple', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'sudo_user'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sudo_user'},{'id': '38', 'type': 'tuple', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': "'su_user'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'su_user'},{'id': '41', 'type': 'tuple', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "'env'"},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'if_statement', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '53']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'debug_meta'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'Building command ({0}): {1}'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '64', 'type': 'argument_list', 'children': ['65', '87']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "' '"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '69', 'type': 'generator_expression', 'children': ['70', '77']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': "'{0}: {1}'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '77', 'type': 'for_in_clause', 'children': ['78', '81']},{'id': '78', 'type': 'pattern_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'debug_meta'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '88', 'type': 'if_statement', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '90', 'type': 'block', 'children': ['91', '117']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'env_string'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "' '"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'list_comprehension', 'children': ['100', '107']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'{0}={1}'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '107', 'type': 'for_in_clause', 'children': ['108', '111']},{'id': '108', 'type': 'pattern_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': "'export {0}; {1}'"},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'env_string'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'shlex_quote'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '134', 'type': 'if_statement', 'children': ['135', '136', '147']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'su_user'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'string', 'children': [], 'value': "'su {0} -c {1}'"},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'su_user'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '147', 'type': 'else_clause', 'children': ['148']},{'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': 'command'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'string', 'children': [], 'value': "'sh -c {0}'"},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '158', 'type': 'if_statement', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'sudo'},{'id': '160', 'type': 'block', 'children': ['161', '167', '177', '189']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'sudo_bits'},{'id': '164', 'type': 'list', 'children': ['165', '166'], 'value': "['sudo', '-H']"},{'id': '165', 'type': 'string', 'children': [], 'value': "'sudo'"},{'id': '166', 'type': 'string', 'children': [], 'value': "'-H'"},{'id': '167', 'type': 'if_statement', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'preserve_sudo_env'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'sudo_bits'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': "'-E'"},{'id': '177', 'type': 'if_statement', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'sudo_user'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'sudo_bits'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'tuple', 'children': ['187', '188']},{'id': '187', 'type': 'string', 'children': [], 'value': "'-u'"},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'sudo_user'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'string', 'children': [], 'value': "'{0} {1}'"},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '196', 'type': 'argument_list', 'children': ['197', '203']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'string', 'children': [], 'value': "' '"},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'sudo_bits'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '204', 'type': 'return_statement', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'command'}
def make_command( command, env=None, su_user=None, sudo=False, sudo_user=None, preserve_sudo_env=False, ): ''' Builds a shell command with various kwargs. ''' debug_meta = {} for key, value in ( ('sudo', sudo), ('sudo_user', sudo_user), ('su_user', su_user), ('env', env), ): if value: debug_meta[key] = value logger.debug('Building command ({0}): {1}'.format(' '.join( '{0}: {1}'.format(key, value) for key, value in six.iteritems(debug_meta) ), command)) if env: env_string = ' '.join([ '{0}={1}'.format(key, value) for key, value in six.iteritems(env) ]) command = 'export {0}; {1}'.format(env_string, command) command = shlex_quote(command) if su_user: command = 'su {0} -c {1}'.format(su_user, command) else: command = 'sh -c {0}'.format(command) if sudo: sudo_bits = ['sudo', '-H'] if preserve_sudo_env: sudo_bits.append('-E') if sudo_user: sudo_bits.extend(('-u', sudo_user)) command = '{0} {1}'.format(' '.join(sudo_bits), command) return command
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_buffer'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'print_output'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'print_func'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '14', '55', '59', '102']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': "'''\n Reads a file-like buffer object into lines and optionally prints the output.\n '''"},{'id': '14', 'type': 'function_definition', 'children': ['15', '16', '18']},{'id': '15', 'type': 'function_name', 'children': [], 'value': '_print'},{'id': '16', 'type': 'parameters', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'if_statement', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'print_output'},{'id': '21', 'type': 'block', 'children': ['22', '38', '50']},{'id': '22', 'type': 'if_statement', 'children': ['23', '24', '32']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'print_func'},{'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': 'formatted_line'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'print_func'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '32', 'type': 'else_clause', 'children': ['33']},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'formatted_line'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'encoded_line'},{'id': '41', 'type': 'call', 'children': ['42', '48']},{'id': '42', 'type': 'attribute', 'children': ['43', '47']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'formatted_line'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'encoded_line'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '58', 'type': 'list', 'children': [], 'value': '[]'},{'id': '59', 'type': 'for_statement', 'children': ['60', '61', '62']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '62', 'type': 'block', 'children': ['63', '82', '90', '97']},{'id': '63', 'type': 'if_statement', 'children': ['64', '72']},{'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': 'line'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'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': 'line'},{'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': 'decode'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_print'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '102', 'type': 'return_statement', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'out'}
def read_buffer(io, print_output=False, print_func=None): ''' Reads a file-like buffer object into lines and optionally prints the output. ''' def _print(line): if print_output: if print_func: formatted_line = print_func(line) else: formatted_line = line encoded_line = unicode(formatted_line).encode('utf-8') print(encoded_line) out = [] for line in io: if not isinstance(line, six.text_type): line = line.decode('utf-8') line = line.strip() out.append(line) _print(line) return out
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'download'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'source_url'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'cache_time'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '26', '37', '52', '56', '105']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'''\n Download files from remote locations.\n + source_url: source URl of the file\n + destination: where to save the file\n + user: user to own the files\n + group: group to own the files\n + mode: permissions of the files\n + cache_time: if the file exists already, re-download after this time (in s)\n + force: always download the file, even if it already exists\n '''"},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'fact'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '37', 'type': 'if_statement', 'children': ['38', '41']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'is'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '40', 'type': 'False', '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': 'OperationError'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'Destination {0} already exists and is not a file'"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'download'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '56', 'type': 'if_statement', 'children': ['57', '60', '65']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'info'},{'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': 'download'},{'id': '64', 'type': 'True', 'children': []},{'id': '65', 'type': 'elif_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'cache_time'},{'id': '67', 'type': 'block', 'children': ['68', '90']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'cache_time'},{'id': '71', 'type': 'binary_operator', 'children': ['72', '84'], 'value': '-'},{'id': '72', 'type': 'call', 'children': ['73', '80']},{'id': '73', 'type': 'attribute', 'children': ['74', '79']},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'fact'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '83', 'type': 'None', 'children': []},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'seconds'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'cache_time'},{'id': '90', 'type': 'if_statement', 'children': ['91', '100']},{'id': '91', 'type': 'boolean_operator', 'children': ['92', '95'], 'value': 'and'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '94', 'type': 'string', 'children': [], 'value': "'mtime'"},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '99'], 'value': '>'},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '98', 'type': 'string', 'children': [], 'value': "'mtime'"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'cache_time'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'download'},{'id': '104', 'type': 'True', 'children': []},{'id': '105', 'type': 'if_statement', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'download'},{'id': '107', 'type': 'block', 'children': ['108', '117', '130']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'yield', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': "'wget -q {0} -O {1}'"},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'source_url'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '117', 'type': 'if_statement', 'children': ['118', '121']},{'id': '118', 'type': 'boolean_operator', 'children': ['119', '120'], 'value': 'or'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'yield', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'chown'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128', '129']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '130', 'type': 'if_statement', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'yield', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'chmod'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'mode'}
def download( state, host, source_url, destination, user=None, group=None, mode=None, cache_time=None, force=False, ): ''' Download files from remote locations. + source_url: source URl of the file + destination: where to save the file + user: user to own the files + group: group to own the files + mode: permissions of the files + cache_time: if the file exists already, re-download after this time (in s) + force: always download the file, even if it already exists ''' info = host.fact.file(destination) if info is False: raise OperationError( 'Destination {0} already exists and is not a file'.format(destination), ) download = force if info is None: download = True elif cache_time: cache_time = host.fact.date.replace(tzinfo=None) - timedelta(seconds=cache_time) if info['mtime'] and info['mtime'] > cache_time: download = True if download: yield 'wget -q {0} -O {1}'.format(source_url, destination) if user or group: yield chown(destination, user, group) if mode: yield chmod(destination, mode)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sync'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17', '20', '23', '26']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'exclude_dir'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'add_deploy_dir'},{'id': '28', 'type': 'True', 'children': []},{'id': '29', 'type': 'block', 'children': ['30', '32', '55', '74', '93', '113', '133', '137', '141', '239', '253', '278', '305']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "'''\n Syncs a local directory with a remote one, with delete support. Note that delete will\n remove extra files on the remote side, but not extra directories.\n + source: local directory to sync\n + destination: remote directory to sync to\n + user: user to own the files and directories\n + group: group to own the files and directories\n + mode: permissions of the files\n + delete: delete remote files not present locally\n + exclude: string or list/tuple of strings to match & exclude files (eg *.pyc)\n + exclude_dir: string or list/tuple of strings to match & exclude directories (eg node_modules)\n '''"},{'id': '32', 'type': 'if_statement', 'children': ['33', '42']},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sep'},{'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': 'source'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'{0}{1}'"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '55', 'type': 'if_statement', 'children': ['56', '61']},{'id': '56', 'type': 'boolean_operator', 'children': ['57', '58'], 'value': 'and'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'add_deploy_dir'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'deploy_dir'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '69', 'type': 'argument_list', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'deploy_dir'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '74', 'type': 'if_statement', 'children': ['75', '82']},{'id': '75', 'type': 'not_operator', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'raise_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': "'No such directory: {0}'"},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '93', 'type': 'if_statement', 'children': ['94', '97']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'is'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '96', 'type': 'None', 'children': []},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'if_statement', 'children': ['99', '107']},{'id': '99', 'type': 'not_operator', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '104', 'type': 'tuple', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '111', 'type': 'list', 'children': ['112'], 'value': '[exclude]'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '113', 'type': 'if_statement', 'children': ['114', '117']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'is'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'exclude_dir'},{'id': '116', 'type': 'None', 'children': []},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'if_statement', 'children': ['119', '127']},{'id': '119', 'type': 'not_operator', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'exclude_dir'},{'id': '124', 'type': 'tuple', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'exclude_dir'},{'id': '131', 'type': 'list', 'children': ['132'], 'value': '[exclude_dir]'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'exclude_dir'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'put_files'},{'id': '136', 'type': 'list', 'children': [], 'value': '[]'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ensure_dirnames'},{'id': '140', 'type': 'list', 'children': [], 'value': '[]'},{'id': '141', 'type': 'for_statement', 'children': ['142', '146', '150']},{'id': '142', 'type': 'pattern_list', 'children': ['143', '144', '145']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '144', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'walk'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '150', 'type': 'block', 'children': ['151', '161', '177', '187']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'remote_dirname'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '160', 'type': 'string', 'children': [], 'value': "''"},{'id': '161', 'type': 'if_statement', 'children': ['162', '175']},{'id': '162', 'type': 'boolean_operator', 'children': ['163', '164'], 'value': 'and'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'exclude_dir'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '166', 'type': 'generator_expression', 'children': ['167', '172']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'fnmatch'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'remote_dirname'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '172', 'type': 'for_in_clause', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'exclude_dir'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'continue_statement', 'children': []},{'id': '177', 'type': 'if_statement', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'remote_dirname'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'ensure_dirnames'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'remote_dirname'},{'id': '187', 'type': 'for_statement', 'children': ['188', '189', '190']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '190', 'type': 'block', 'children': ['191', '201', '217']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'full_filename'},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '201', 'type': 'if_statement', 'children': ['202', '215']},{'id': '202', 'type': 'boolean_operator', 'children': ['203', '204'], 'value': 'and'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '206', 'type': 'generator_expression', 'children': ['207', '212']},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'fnmatch'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'full_filename'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '212', 'type': 'for_in_clause', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'continue_statement', 'children': []},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'put_files'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'tuple', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'full_filename'},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '229', 'type': 'generator_expression', 'children': ['230', '231', '237']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '231', 'type': 'for_in_clause', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '233', 'type': 'tuple', 'children': ['234', '235', '236']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'remote_dirname'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '237', 'type': 'if_clause', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'yield', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '243', 'type': 'argument_list', 'children': ['244', '245', '246', '247', '250']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '253', 'type': 'for_statement', 'children': ['254', '255', '256']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'ensure_dirnames'},{'id': '256', 'type': 'block', 'children': ['257']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'yield', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263', '264', '272', '275']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'tuple', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '272', 'type': 'keyword_argument', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '278', 'type': 'for_statement', 'children': ['279', '282', '283']},{'id': '279', 'type': 'pattern_list', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'local_filename'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'put_files'},{'id': '283', 'type': 'block', 'children': ['284']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'yield', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'put'},{'id': '288', 'type': 'argument_list', 'children': ['289', '290', '291', '292', '293', '296', '299', '302']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'local_filename'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'add_deploy_dir'},{'id': '304', 'type': 'False', 'children': []},{'id': '305', 'type': 'if_statement', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '307', 'type': 'block', 'children': ['308', '324', '337', '343']},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'assignment', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'remote_filenames'},{'id': '311', 'type': 'call', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '313', 'type': 'argument_list', 'children': ['314']},{'id': '314', 'type': 'boolean_operator', 'children': ['315', '323'], 'value': 'or'},{'id': '315', 'type': 'call', 'children': ['316', '321']},{'id': '316', 'type': 'attribute', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'fact'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'find_files'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'destination'},{'id': '323', 'type': 'list', 'children': [], 'value': '[]'},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'wanted_filenames'},{'id': '327', 'type': 'call', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'list_comprehension', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '332', 'type': 'for_in_clause', 'children': ['333', '336']},{'id': '333', 'type': 'pattern_list', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'put_files'},{'id': '337', 'type': 'expression_statement', 'children': ['338']},{'id': '338', 'type': 'assignment', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'files_to_delete'},{'id': '340', 'type': 'binary_operator', 'children': ['341', '342'], 'value': '-'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'remote_filenames'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'wanted_filenames'},{'id': '343', 'type': 'for_statement', 'children': ['344', '345', '346']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'files_to_delete'},{'id': '346', 'type': 'block', 'children': ['347', '363']},{'id': '347', 'type': 'if_statement', 'children': ['348', '361']},{'id': '348', 'type': 'boolean_operator', 'children': ['349', '350'], 'value': 'and'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '350', 'type': 'call', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '352', 'type': 'generator_expression', 'children': ['353', '358']},{'id': '353', 'type': 'call', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'fnmatch'},{'id': '355', 'type': 'argument_list', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '358', 'type': 'for_in_clause', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '361', 'type': 'block', 'children': ['362']},{'id': '362', 'type': 'continue_statement', 'children': []},{'id': '363', 'type': 'expression_statement', 'children': ['364']},{'id': '364', 'type': 'yield', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '367', 'type': 'argument_list', 'children': ['368', '369', '370', '371']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '371', 'type': 'keyword_argument', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'present'},{'id': '373', 'type': 'False', 'children': []}
def sync( state, host, source, destination, user=None, group=None, mode=None, delete=False, exclude=None, exclude_dir=None, add_deploy_dir=True, ): ''' Syncs a local directory with a remote one, with delete support. Note that delete will remove extra files on the remote side, but not extra directories. + source: local directory to sync + destination: remote directory to sync to + user: user to own the files and directories + group: group to own the files and directories + mode: permissions of the files + delete: delete remote files not present locally + exclude: string or list/tuple of strings to match & exclude files (eg *.pyc) + exclude_dir: string or list/tuple of strings to match & exclude directories (eg node_modules) ''' if not source.endswith(path.sep): source = '{0}{1}'.format(source, path.sep) if add_deploy_dir and state.deploy_dir: source = path.join(state.deploy_dir, source) if not path.isdir(source): raise IOError('No such directory: {0}'.format(source)) if exclude is not None: if not isinstance(exclude, (list, tuple)): exclude = [exclude] if exclude_dir is not None: if not isinstance(exclude_dir, (list, tuple)): exclude_dir = [exclude_dir] put_files = [] ensure_dirnames = [] for dirname, _, filenames in walk(source): remote_dirname = dirname.replace(source, '') if exclude_dir and any(fnmatch(remote_dirname, match) for match in exclude_dir): continue if remote_dirname: ensure_dirnames.append(remote_dirname) for filename in filenames: full_filename = path.join(dirname, filename) if exclude and any(fnmatch(full_filename, match) for match in exclude): continue put_files.append(( full_filename, '/'.join( item for item in (destination, remote_dirname, filename) if item ), )) yield directory( state, host, destination, user=user, group=group, ) for dirname in ensure_dirnames: yield directory( state, host, '/'.join((destination, dirname)), user=user, group=group, ) for local_filename, remote_filename in put_files: yield put( state, host, local_filename, remote_filename, user=user, group=group, mode=mode, add_deploy_dir=False, ) if delete: remote_filenames = set(host.fact.find_files(destination) or []) wanted_filenames = set([remote_filename for _, remote_filename in put_files]) files_to_delete = remote_filenames - wanted_filenames for filename in files_to_delete: if exclude and any(fnmatch(filename, match) for match in exclude): continue yield file(state, host, filename, present=False)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'put'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'local_filename'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'add_deploy_dir'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '23', '78', '85', '96']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': "'''\n Copy a local file to the remote system.\n + local_filename: local filename\n + remote_filename: remote filename\n + user: user to own the files\n + group: group to own the files\n + mode: permissions of the files\n '''"},{'id': '23', 'type': 'if_statement', 'children': ['24', '29', '34']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'local_filename'},{'id': '28', 'type': 'string', 'children': [], 'value': "'read'"},{'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': 'local_file'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'local_filename'},{'id': '34', 'type': 'else_clause', 'children': ['35']},{'id': '35', 'type': 'block', 'children': ['36', '55', '59']},{'id': '36', 'type': 'if_statement', 'children': ['37', '42']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '39'], 'value': 'and'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'add_deploy_dir'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'deploy_dir'},{'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': 'local_filename'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '50', 'type': 'argument_list', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'deploy_dir'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'local_filename'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'local_file'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'local_filename'},{'id': '59', 'type': 'if_statement', 'children': ['60', '67']},{'id': '60', 'type': 'not_operator', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'local_file'},{'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': 'IOError'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': "'No such file: {0}'"},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'local_file'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ensure_mode_int'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'remote_file'},{'id': '88', 'type': 'call', 'children': ['89', '94']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'fact'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '96', 'type': 'if_statement', 'children': ['97', '99', '128']},{'id': '97', 'type': 'not_operator', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'remote_file'},{'id': '99', 'type': 'block', 'children': ['100', '105', '118']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'yield', 'children': ['102']},{'id': '102', 'type': 'tuple', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'local_file'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '105', 'type': 'if_statement', 'children': ['106', '109']},{'id': '106', 'type': 'boolean_operator', 'children': ['107', '108'], 'value': 'or'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'yield', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'chown'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116', '117']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '118', 'type': 'if_statement', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'yield', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'chmod'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '128', 'type': 'else_clause', 'children': ['129']},{'id': '129', 'type': 'block', 'children': ['130', '137', '148']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'local_sum'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'get_file_sha1'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'local_filename'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'remote_sum'},{'id': '140', 'type': 'call', 'children': ['141', '146']},{'id': '141', 'type': 'attribute', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'fact'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sha1_file'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '148', 'type': 'if_statement', 'children': ['149', '152', '181']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '!='},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'local_sum'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'remote_sum'},{'id': '152', 'type': 'block', 'children': ['153', '158', '171']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'yield', 'children': ['155']},{'id': '155', 'type': 'tuple', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'local_file'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '158', 'type': 'if_statement', 'children': ['159', '162']},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '161'], 'value': 'or'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'yield', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'chown'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169', '170']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '171', 'type': 'if_statement', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'yield', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'chmod'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '181', 'type': 'else_clause', 'children': ['182']},{'id': '182', 'type': 'block', 'children': ['183', '199']},{'id': '183', 'type': 'if_statement', 'children': ['184', '191']},{'id': '184', 'type': 'boolean_operator', 'children': ['185', '186'], 'value': 'and'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '190'], 'value': '!='},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'remote_file'},{'id': '189', 'type': 'string', 'children': [], 'value': "'mode'"},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'yield', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'chmod'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '199', 'type': 'if_statement', 'children': ['200', '218']},{'id': '200', 'type': '()', 'children': ['201']},{'id': '201', 'type': 'boolean_operator', 'children': ['202', '210'], 'value': 'or'},{'id': '202', 'type': '()', 'children': ['203']},{'id': '203', 'type': 'boolean_operator', 'children': ['204', '205'], 'value': 'and'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '205', 'type': 'comparison_operator', 'children': ['206', '209'], 'value': '!='},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'remote_file'},{'id': '208', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '210', 'type': '()', 'children': ['211']},{'id': '211', 'type': 'boolean_operator', 'children': ['212', '213'], 'value': 'and'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '217'], 'value': '!='},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'remote_file'},{'id': '216', 'type': 'string', 'children': [], 'value': "'group'"},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'yield', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'chown'},{'id': '223', 'type': 'argument_list', 'children': ['224', '225', '226']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'remote_filename'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'group'}
def put( state, host, local_filename, remote_filename, user=None, group=None, mode=None, add_deploy_dir=True, ): ''' Copy a local file to the remote system. + local_filename: local filename + remote_filename: remote filename + user: user to own the files + group: group to own the files + mode: permissions of the files ''' if hasattr(local_filename, 'read'): local_file = local_filename else: if add_deploy_dir and state.deploy_dir: local_filename = path.join(state.deploy_dir, local_filename) local_file = local_filename if not path.isfile(local_file): raise IOError('No such file: {0}'.format(local_file)) mode = ensure_mode_int(mode) remote_file = host.fact.file(remote_filename) if not remote_file: yield (local_file, remote_filename) if user or group: yield chown(remote_filename, user, group) if mode: yield chmod(remote_filename, mode) else: local_sum = get_file_sha1(local_filename) remote_sum = host.fact.sha1_file(remote_filename) if local_sum != remote_sum: yield (local_file, remote_filename) if user or group: yield chown(remote_filename, user, group) if mode: yield chmod(remote_filename, mode) else: if mode and remote_file['mode'] != mode: yield chmod(remote_filename, mode) if ( (user and remote_file['user'] != user) or (group and remote_file['group'] != group) ): yield chown(remote_filename, user, group)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_run_single_op'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'op_hash'},{'id': '6', 'type': 'block', 'children': ['7', '9', '17', '21', '33', '45', '108', '114', '300', '313']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Run a single operation for all servers. Can be configured to run in serial.\n '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'op_meta'},{'id': '12', 'type': 'subscript', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'op_meta'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'op_hash'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'op_types'},{'id': '20', 'type': 'list', 'children': [], 'value': '[]'},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'op_meta'},{'id': '24', 'type': 'string', 'children': [], 'value': "'serial'"},{'id': '25', 'type': 'block', 'children': ['26']},{'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': 'op_types'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': "'serial'"},{'id': '33', 'type': 'if_statement', 'children': ['34', '37']},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'op_meta'},{'id': '36', 'type': 'string', 'children': [], 'value': "'run_once'"},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'op_types'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "'run once'"},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'{0} {1} {2}'"},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '55', 'type': 'argument_list', 'children': ['56', '81', '97']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '60', 'type': 'argument_list', 'children': ['61', '80']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "'--> Starting{0}operation:'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'conditional_expression', 'children': ['67', '78', '79'], 'value': 'if'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': "' {0} '"},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': "', '"},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'op_types'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'op_types'},{'id': '79', 'type': 'string', 'children': [], 'value': "' '"},{'id': '80', 'type': 'string', 'children': [], 'value': "'blue'"},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'click'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '85', 'type': 'argument_list', 'children': ['86', '94']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "', '"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'op_meta'},{'id': '93', 'type': 'string', 'children': [], 'value': "'names'"},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'bold'},{'id': '96', 'type': 'True', 'children': []},{'id': '97', 'type': 'conditional_expression', 'children': ['98', '104', '107'], 'value': 'if'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'op_meta'},{'id': '103', 'type': 'string', 'children': [], 'value': "'args'"},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'op_meta'},{'id': '106', 'type': 'string', 'children': [], 'value': "'args'"},{'id': '107', 'type': 'string', 'children': [], 'value': "''"},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'failed_hosts'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '113', 'type': 'argument_list', 'children': []},{'id': '114', 'type': 'if_statement', 'children': ['115', '118', '163']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'op_meta'},{'id': '117', 'type': 'string', 'children': [], 'value': "'serial'"},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'with_statement', 'children': ['120', '131']},{'id': '120', 'type': 'with_clause', 'children': ['121']},{'id': '121', 'type': 'with_item', 'children': ['122']},{'id': '122', 'type': 'as_pattern', 'children': ['123', '129']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'progress_spinner'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'inventory'},{'id': '129', 'type': 'as_pattern_target', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'progress'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'for_statement', 'children': ['133', '134', '137']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'inventory'},{'id': '137', 'type': 'block', 'children': ['138', '147', '152']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_run_server_op'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145', '146']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'op_hash'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'progress'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '152', 'type': 'if_statement', 'children': ['153', '155']},{'id': '153', 'type': 'not_operator', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'failed_hosts'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '163', 'type': 'else_clause', 'children': ['164']},{'id': '164', 'type': 'block', 'children': ['165', '172', '215']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'batches'},{'id': '168', 'type': 'list', 'children': ['169'], 'value': '[state.inventory]'},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'inventory'},{'id': '172', 'type': 'if_statement', 'children': ['173', '176']},{'id': '173', 'type': 'subscript', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'op_meta'},{'id': '175', 'type': 'string', 'children': [], 'value': "'parallel'"},{'id': '176', 'type': 'block', 'children': ['177', '183', '192']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'parallel'},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'op_meta'},{'id': '182', 'type': 'string', 'children': [], 'value': "'parallel'"},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'hosts'},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'inventory'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'batches'},{'id': '195', 'type': 'list_comprehension', 'children': ['196', '204']},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'hosts'},{'id': '198', 'type': 'slice', 'children': ['199', '200', '201']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '200', 'type': 'colon', 'children': []},{'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '+'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'parallel'},{'id': '204', 'type': 'for_in_clause', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210', '214']},{'id': '209', 'type': 'integer', 'children': [], 'value': '0'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'hosts'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'parallel'},{'id': '215', 'type': 'for_statement', 'children': ['216', '217', '218']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'batches'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'with_statement', 'children': ['220', '229']},{'id': '220', 'type': 'with_clause', 'children': ['221']},{'id': '221', 'type': 'with_item', 'children': ['222']},{'id': '222', 'type': 'as_pattern', 'children': ['223', '227']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'progress_spinner'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '227', 'type': 'as_pattern_target', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'progress'},{'id': '229', 'type': 'block', 'children': ['230', '250', '274']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'greenlet_to_host'},{'id': '233', 'type': 'dictionary_comprehension', 'children': ['234', '247']},{'id': '234', 'type': 'pair', 'children': ['235', '246']},{'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': 'state'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'spawn'},{'id': '241', 'type': 'argument_list', 'children': ['242', '243', '244', '245']},{'id': '242', 'type': 'identifier', 'children': [], 'value': '_run_server_op'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'op_hash'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '247', 'type': 'for_in_clause', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'batch'},{'id': '250', 'type': 'for_statement', 'children': ['251', '252', '262']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'greenlet'},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'gevent'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'iwait'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'greenlet_to_host'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '261', 'type': 'argument_list', 'children': []},{'id': '262', 'type': 'block', 'children': ['263', '269']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'greenlet_to_host'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'greenlet'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'progress'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '274', 'type': 'for_statement', 'children': ['275', '278', '284']},{'id': '275', 'type': 'pattern_list', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'greenlet'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'greenlet_to_host'},{'id': '284', 'type': 'block', 'children': ['285']},{'id': '285', 'type': 'if_statement', 'children': ['286', '292']},{'id': '286', 'type': 'not_operator', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'greenlet'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '291', 'type': 'argument_list', 'children': []},{'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': 'failed_hosts'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '300', 'type': 'if_statement', 'children': ['301', '305']},{'id': '301', 'type': 'not_operator', 'children': ['302']},{'id': '302', 'type': 'subscript', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'op_meta'},{'id': '304', 'type': 'string', 'children': [], 'value': "'ignore_errors'"},{'id': '305', 'type': 'block', 'children': ['306']},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'fail_hosts'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'failed_hosts'},{'id': '313', 'type': 'if_statement', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'pyinfra'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'is_cli'},{'id': '317', 'type': 'block', 'children': ['318']},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'call', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '321', 'type': 'argument_list', 'children': []}
def _run_single_op(state, op_hash): ''' Run a single operation for all servers. Can be configured to run in serial. ''' op_meta = state.op_meta[op_hash] op_types = [] if op_meta['serial']: op_types.append('serial') if op_meta['run_once']: op_types.append('run once') logger.info('{0} {1} {2}'.format( click.style('--> Starting{0}operation:'.format( ' {0} '.format(', '.join(op_types)) if op_types else ' ', ), 'blue'), click.style(', '.join(op_meta['names']), bold=True), tuple(op_meta['args']) if op_meta['args'] else '', )) failed_hosts = set() if op_meta['serial']: with progress_spinner(state.inventory) as progress: for host in state.inventory: result = _run_server_op(state, host, op_hash) progress(host) if not result: failed_hosts.add(host) else: batches = [state.inventory] if op_meta['parallel']: parallel = op_meta['parallel'] hosts = list(state.inventory) batches = [ hosts[i:i + parallel] for i in range(0, len(hosts), parallel) ] for batch in batches: with progress_spinner(batch) as progress: greenlet_to_host = { state.pool.spawn(_run_server_op, state, host, op_hash): host for host in batch } for greenlet in gevent.iwait(greenlet_to_host.keys()): host = greenlet_to_host[greenlet] progress(host) for greenlet, host in six.iteritems(greenlet_to_host): if not greenlet.get(): failed_hosts.add(host) if not op_meta['ignore_errors']: state.fail_hosts(failed_hosts) if pyinfra.is_cli: print()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'send'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '45', '67']},{'id': '6', 'type': 'if_statement', 'children': ['7', '11', '18']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_receive_has_been_called'},{'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': 'all_addrs'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_dest_addrs'},{'id': '18', 'type': 'else_clause', 'children': ['19']},{'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': 'all_addrs'},{'id': '23', 'type': 'list_comprehension', 'children': ['24', '25', '39']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '25', 'type': 'for_in_clause', 'children': ['26', '29']},{'id': '26', 'type': 'tuple_pattern', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '38']},{'id': '33', 'type': 'attribute', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_id_to_addr'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'if_clause', 'children': ['40']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'in'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_remaining_ids'},{'id': '45', 'type': 'if_statement', 'children': ['46', '51']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': 'is'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_last_used_id'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_last_used_id'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '66'], 'value': '&'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'integer', 'children': [], 'value': '0xffff'},{'id': '67', 'type': 'for_statement', 'children': ['68', '69', '70']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'addr'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'all_addrs'},{'id': '70', 'type': 'block', 'children': ['71', '84', '94']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': '_last_used_id'},{'id': '76', 'type': 'binary_operator', 'children': ['77', '83'], 'value': '&'},{'id': '77', 'type': '()', 'children': ['78']},{'id': '78', 'type': 'binary_operator', 'children': ['79', '82'], 'value': '+'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_last_used_id'},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'integer', 'children': [], 'value': '0xffff'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '93']},{'id': '86', 'type': 'subscript', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_id_to_addr'},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_last_used_id'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'addr'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_send_ping'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'addr'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'struct'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': '"d"'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '113', 'type': 'argument_list', 'children': []}
def send(self): if not self._receive_has_been_called: all_addrs = self._dest_addrs else: all_addrs = [a for (i, a) in list(self._id_to_addr.items()) if i in self._remaining_ids] if self._last_used_id is None: self._last_used_id = int(time.time()) & 0xffff for addr in all_addrs: self._last_used_id = (self._last_used_id + 1) & 0xffff self._id_to_addr[self._last_used_id] = addr self._send_ping(addr, payload=struct.pack("d", time.time()))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'registers'},{'id': '6', 'type': 'block', 'children': ['7', '19', '38', '52', '62', '85', '95', '119', '132', '143', '155', '161', '171', '177', '185', '224', '237', '247', '253', '263', '275', '281', '291', '297', '311', '325', '350']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '10', 'type': 'dictionary', 'children': ['11', '16']},{'id': '11', 'type': 'pair', 'children': ['12', '13']},{'id': '12', 'type': 'string', 'children': [], 'value': "'ip'"},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ip'},{'id': '16', 'type': 'pair', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': "'connected'"},{'id': '18', 'type': 'True', 'children': []},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'BinaryPayloadDecoder'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'fromRegisters'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28', '33']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'registers'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'byteorder'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'Endian'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'Big'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'wordorder'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'Endian'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'Little'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '41', 'type': 'list', 'children': ['42', '47'], 'value': '[decoder.decode_bits(), decoder.decode_bits()]'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'decode_bits'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'decode_bits'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'reg_40001'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '59'], 'value': '+'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'monitor_integer'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '67', 'type': 'generator_expression', 'children': ['68', '71', '83']},{'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '<<'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '71', 'type': 'for_in_clause', 'children': ['72', '75']},{'id': '72', 'type': 'pattern_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'reg_40001'},{'id': '80', 'type': 'slice', 'children': ['81', '82']},{'id': '81', 'type': 'colon', 'children': []},{'id': '82', 'type': 'integer', 'children': [], 'value': '4'},{'id': '83', 'type': 'if_clause', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'b'},{'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': 'result'},{'id': '89', 'type': 'string', 'children': [], 'value': "'state'"},{'id': '90', 'type': 'subscript', 'children': ['91', '94']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '93', 'type': 'string', 'children': [], 'value': "'monitor state'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'monitor_integer'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'fault_integer'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '100', 'type': 'generator_expression', 'children': ['101', '104', '117']},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '<<'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '104', 'type': 'for_in_clause', 'children': ['105', '108']},{'id': '105', 'type': 'pattern_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'reg_40001'},{'id': '113', 'type': 'slice', 'children': ['114', '115', '116']},{'id': '114', 'type': 'integer', 'children': [], 'value': '4'},{'id': '115', 'type': 'colon', 'children': []},{'id': '116', 'type': 'integer', 'children': [], 'value': '6'},{'id': '117', 'type': 'if_clause', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '124']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '123', 'type': 'string', 'children': [], 'value': "'fault'"},{'id': '124', 'type': 'dictionary', 'children': ['125']},{'id': '125', 'type': 'pair', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '127', 'type': 'subscript', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '130', 'type': 'string', 'children': [], 'value': "'fault status'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'fault_integer'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '137']},{'id': '134', 'type': 'pattern_list', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'low'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'reg_40001'},{'id': '139', 'type': 'slice', 'children': ['140', '141', '142']},{'id': '140', 'type': 'integer', 'children': [], 'value': '6'},{'id': '141', 'type': 'colon', 'children': []},{'id': '142', 'type': 'integer', 'children': [], 'value': '8'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '147', 'type': 'string', 'children': [], 'value': "'alarm'"},{'id': '148', 'type': 'subscript', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '151', 'type': 'string', 'children': [], 'value': "'alarm level'"},{'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '+'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'low'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'augmented_assignment', 'children': ['157', '160'], 'value': '+='},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '159', 'type': 'identifier', 'children': [], 'value': '_pointer'},{'id': '160', 'type': 'integer', 'children': [], 'value': '2'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '166']},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '165', 'type': 'string', 'children': [], 'value': "'concentration'"},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'decode_32bit_float'},{'id': '170', 'type': 'argument_list', 'children': []},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'augmented_assignment', 'children': ['173', '176'], 'value': '+='},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_pointer'},{'id': '176', 'type': 'integer', 'children': [], 'value': '2'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'fault_number'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'decode_16bit_uint'},{'id': '184', 'type': 'argument_list', 'children': []},{'id': '185', 'type': 'if_statement', 'children': ['186', '189']},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': '!='},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'fault_number'},{'id': '188', 'type': 'integer', 'children': [], 'value': '0'},{'id': '189', 'type': 'block', 'children': ['190', '205', '213']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '201'], 'value': '+'},{'id': '194', 'type': '()', 'children': ['195']},{'id': '195', 'type': 'conditional_expression', 'children': ['196', '197', '200'], 'value': 'if'},{'id': '196', 'type': 'string', 'children': [], 'value': "'m'"},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': '<'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'fault_number'},{'id': '199', 'type': 'integer', 'children': [], 'value': '30'},{'id': '200', 'type': 'string', 'children': [], 'value': "'F'"},{'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': 'fault_number'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '212']},{'id': '207', 'type': 'subscript', 'children': ['208', '211']},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '210', 'type': 'string', 'children': [], 'value': "'fault'"},{'id': '211', 'type': 'string', 'children': [], 'value': "'code'"},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '220']},{'id': '215', 'type': 'attribute', 'children': ['216', '219']},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '218', 'type': 'string', 'children': [], 'value': "'fault'"},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'subscript', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'faults'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'unit_bit'},{'id': '227', 'type': 'call', 'children': ['228', '235']},{'id': '228', 'type': 'attribute', 'children': ['229', '234']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'decode_bits'},{'id': '233', 'type': 'argument_list', 'children': []},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'True', 'children': []},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '242']},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '241', 'type': 'string', 'children': [], 'value': "'units'"},{'id': '242', 'type': 'subscript', 'children': ['243', '246']},{'id': '243', 'type': 'subscript', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '245', 'type': 'string', 'children': [], 'value': "'concentration unit'"},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'unit_bit'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'augmented_assignment', 'children': ['249', '252'], 'value': '+='},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '251', 'type': 'identifier', 'children': [], 'value': '_pointer'},{'id': '252', 'type': 'integer', 'children': [], 'value': '1'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '258']},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '257', 'type': 'string', 'children': [], 'value': "'temperature'"},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'decode_16bit_int'},{'id': '262', 'type': 'argument_list', 'children': []},{'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': 'result'},{'id': '267', 'type': 'string', 'children': [], 'value': "'life'"},{'id': '268', 'type': 'binary_operator', 'children': ['269', '274'], 'value': '/'},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'decode_16bit_uint'},{'id': '273', 'type': 'argument_list', 'children': []},{'id': '274', 'type': 'float', 'children': [], 'value': '24.0'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'augmented_assignment', 'children': ['277', '280'], 'value': '+='},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '279', 'type': 'identifier', 'children': [], 'value': '_pointer'},{'id': '280', 'type': 'integer', 'children': [], 'value': '2'},{'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': 'result'},{'id': '285', 'type': 'string', 'children': [], 'value': "'flow'"},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'decode_16bit_uint'},{'id': '290', 'type': 'argument_list', 'children': []},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'augmented_assignment', 'children': ['293', '296'], 'value': '+='},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '295', 'type': 'identifier', 'children': [], 'value': '_pointer'},{'id': '296', 'type': 'integer', 'children': [], 'value': '2'},{'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': 'result'},{'id': '301', 'type': 'string', 'children': [], 'value': "'low-alarm threshold'"},{'id': '302', 'type': 'call', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '304', 'type': 'argument_list', 'children': ['305', '310']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'decode_32bit_float'},{'id': '309', 'type': 'argument_list', 'children': []},{'id': '310', 'type': 'integer', 'children': [], 'value': '6'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'assignment', 'children': ['313', '316']},{'id': '313', 'type': 'subscript', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '315', 'type': 'string', 'children': [], 'value': "'high-alarm threshold'"},{'id': '316', 'type': 'call', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '318', 'type': 'argument_list', 'children': ['319', '324']},{'id': '319', 'type': 'call', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'decoder'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'decode_32bit_float'},{'id': '323', 'type': 'argument_list', 'children': []},{'id': '324', 'type': 'integer', 'children': [], 'value': '6'},{'id': '325', 'type': 'if_statement', 'children': ['326', '331']},{'id': '326', 'type': 'comparison_operator', 'children': ['327', '330'], 'value': '=='},{'id': '327', 'type': 'subscript', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '329', 'type': 'string', 'children': [], 'value': "'units'"},{'id': '330', 'type': 'string', 'children': [], 'value': "'ppb'"},{'id': '331', 'type': 'block', 'children': ['332', '338', '344']},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'augmented_assignment', 'children': ['334', '337'], 'value': '*='},{'id': '334', 'type': 'subscript', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '336', 'type': 'string', 'children': [], 'value': "'concentration'"},{'id': '337', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'augmented_assignment', 'children': ['340', '343'], 'value': '*='},{'id': '340', 'type': 'subscript', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '342', 'type': 'string', 'children': [], 'value': "'low-alarm threshold'"},{'id': '343', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'augmented_assignment', 'children': ['346', '349'], 'value': '*='},{'id': '346', 'type': 'subscript', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '348', 'type': 'string', 'children': [], 'value': "'high-alarm threshold'"},{'id': '349', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '350', 'type': 'return_statement', 'children': ['351']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'result'}
def _parse(self, registers): result = {'ip': self.ip, 'connected': True} decoder = BinaryPayloadDecoder.fromRegisters(registers, byteorder=Endian.Big, wordorder=Endian.Little) b = [decoder.decode_bits(), decoder.decode_bits()] reg_40001 = b[1] + b[0] monitor_integer = sum(1 << i for i, b in enumerate(reg_40001[:4]) if b) result['state'] = options['monitor state'][monitor_integer] fault_integer = sum(1 << i for i, b in enumerate(reg_40001[4:6]) if b) result['fault'] = {'status': options['fault status'][fault_integer]} low, high = reg_40001[6:8] result['alarm'] = options['alarm level'][low + high] decoder._pointer += 2 result['concentration'] = decoder.decode_32bit_float() decoder._pointer += 2 fault_number = decoder.decode_16bit_uint() if fault_number != 0: code = ('m' if fault_number < 30 else 'F') + str(fault_number) result['fault']['code'] = code result['fault'].update(faults[code]) unit_bit = decoder.decode_bits().index(True) result['units'] = options['concentration unit'][unit_bit] decoder._pointer += 1 result['temperature'] = decoder.decode_16bit_int() result['life'] = decoder.decode_16bit_uint() / 24.0 decoder._pointer += 2 result['flow'] = decoder.decode_16bit_uint() decoder._pointer += 2 result['low-alarm threshold'] = round(decoder.decode_32bit_float(), 6) result['high-alarm threshold'] = round(decoder.decode_32bit_float(), 6) if result['units'] == 'ppb': result['concentration'] *= 1000 result['low-alarm threshold'] *= 1000 result['high-alarm threshold'] *= 1000 return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ParseCFlags'},{'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': 'start_line'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'block', 'children': ['9', '13', '17', '21', '217']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'modname'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'modlist'},{'id': '16', 'type': 'list', 'children': [], 'value': '[]'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '33']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'line_num'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'start_line'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '33', 'type': 'block', 'children': ['34', '46', '65', '76', '139', '150', '191']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '37', 'type': 'call', 'children': ['38', '45']},{'id': '38', 'type': 'attribute', 'children': ['39', '44']},{'id': '39', 'type': 'subscript', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'line_num'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'if_statement', 'children': ['47', '49']},{'id': '47', 'type': 'not_operator', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '49', 'type': 'block', 'children': ['50', '64']},{'id': '50', 'type': 'if_statement', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '52', 'type': 'block', 'children': ['53', '60']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'modlist'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'continue_statement', 'children': []},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'mobj'},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'module_c_re'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '76', 'type': 'if_statement', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'mobj'},{'id': '78', 'type': 'block', 'children': ['79', '88', '97', '107', '116', '126', '134', '138']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'modname'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'mobj'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'logging'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '%'},{'id': '95', 'type': 'string', 'children': [], 'value': "'Module: %s'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '97', 'type': 'if_statement', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '99', 'type': 'block', 'children': ['100']},{'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': 'modlist'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '114']},{'id': '109', 'type': 'attribute', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'module_list'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'modname'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '123']},{'id': '118', 'type': 'attribute', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'modname'},{'id': '125', 'type': 'list', 'children': [], 'value': '[]'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'modlist'},{'id': '129', 'type': 'subscript', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'modname'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '137', 'type': 'None', 'children': []},{'id': '138', 'type': 'continue_statement', 'children': []},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'mobj'},{'id': '142', 'type': 'call', 'children': ['143', '148']},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'flag_c_re'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '150', 'type': 'if_statement', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'mobj'},{'id': '152', 'type': 'block', 'children': ['153', '163', '172', '190']},{'id': '153', 'type': 'if_statement', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'modlist'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'flag'},{'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': 'logging'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'binary_operator', 'children': ['170', '171'], 'value': '%'},{'id': '170', 'type': 'string', 'children': [], 'value': "'Flag: %s'"},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'Flag'},{'id': '177', 'type': 'argument_list', 'children': ['178', '184']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'mobj'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'integer', 'children': [], 'value': '1'},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'mobj'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'integer', 'children': [], 'value': '2'},{'id': '190', 'type': 'continue_statement', 'children': []},{'id': '191', 'type': 'if_statement', 'children': ['192', '193', '206']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'augmented_assignment', 'children': ['196', '199'], 'value': '+='},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '+'},{'id': '200', 'type': 'string', 'children': [], 'value': "' '"},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'else_clause', 'children': ['207']},{'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': 'logging'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '%'},{'id': '215', 'type': 'string', 'children': [], 'value': "'Extra: %s'"},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '217', 'type': 'if_statement', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'modlist'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'flag'}
def ParseCFlags(self, start_line=0): modname = None modlist = [] flag = None for line_num in range(start_line, len(self.output)): line = self.output[line_num].rstrip() if not line: if flag: modlist.append(flag) flag = None continue mobj = self.module_c_re.match(line) if mobj: modname = mobj.group(1) logging.debug('Module: %s' % line) if flag: modlist.append(flag) self.module_list.append(modname) self.modules.setdefault(modname, []) modlist = self.modules[modname] flag = None continue mobj = self.flag_c_re.match(line) if mobj: if flag: modlist.append(flag) logging.debug('Flag: %s' % line) flag = Flag(mobj.group(1), mobj.group(2)) continue if flag: flag.help += ' ' + line.strip() else: logging.info('Extra: %s' % line) if flag: modlist.append(flag)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'DEFINE_alias'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'original_name'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'flag_values'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'FLAGS'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '23', '29', '51', '85', '93']},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'not'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'original_name'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'flag_values'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'raise_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'UnrecognizedFlagError'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'original_name'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'flag_values'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'original_name'},{'id': '29', 'type': 'class_definition', 'children': ['30', '31', '33']},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_Parser'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ArgumentParser'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'function_definition', 'children': ['35', '36', '39']},{'id': '35', 'type': 'function_name', 'children': [], 'value': 'parse'},{'id': '36', 'type': 'parameters', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'argument'},{'id': '39', 'type': 'block', 'children': ['40', '47']},{'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': 'flag'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'argument'},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '51', 'type': 'class_definition', 'children': ['52', '53', '55']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_FlagAlias'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'Flag'},{'id': '55', 'type': 'block', 'children': ['56', '68']},{'id': '56', 'type': 'decorated_definition', 'children': ['57', '59']},{'id': '57', 'type': 'decorator', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '59', 'type': 'function_definition', 'children': ['60', '61', '63']},{'id': '60', 'type': 'function_name', 'children': [], 'value': 'value'},{'id': '61', 'type': 'parameters', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '68', 'type': 'decorated_definition', 'children': ['69', '73']},{'id': '69', 'type': 'decorator', 'children': ['70']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'setter'},{'id': '73', 'type': 'function_definition', 'children': ['74', '75', '78']},{'id': '74', 'type': 'function_name', 'children': [], 'value': 'value'},{'id': '75', 'type': 'parameters', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '78', 'type': 'block', 'children': ['79']},{'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': 'flag'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'help_msg'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '%'},{'id': '89', 'type': 'string', 'children': [], 'value': "'Alias for --%s.'"},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'DEFINE_flag'},{'id': '96', 'type': 'argument_list', 'children': ['97', '116', '117']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_FlagAlias'},{'id': '99', 'type': 'argument_list', 'children': ['100', '103', '106', '107', '110', '111']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_Parser'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'help_msg'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'boolean'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'boolean'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'flag_values'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'module_name'}
def DEFINE_alias(name, original_name, flag_values=FLAGS, module_name=None): if original_name not in flag_values: raise UnrecognizedFlagError(original_name) flag = flag_values[original_name] class _Parser(ArgumentParser): def parse(self, argument): flag.parse(argument) return flag.value class _FlagAlias(Flag): @property def value(self): return flag.value @value.setter def value(self, value): flag.value = value help_msg = 'Alias for --%s.' % flag.name DEFINE_flag(_FlagAlias(_Parser(), flag.serializer, name, flag.default, help_msg, boolean=flag.boolean), flag_values, module_name)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'acquire'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'lifetime'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'mechs'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '16', 'type': 'string', 'children': [], 'value': "'both'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '73']},{'id': '21', 'type': 'if_statement', 'children': ['22', '25', '38']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'rcreds'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'acquire_cred'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35', '36', '37']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'lifetime'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'mechs'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '38', 'type': 'else_clause', 'children': ['39']},{'id': '39', 'type': 'block', 'children': ['40', '53', '60']},{'id': '40', 'type': 'if_statement', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'rcred_cred_store'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'raise_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'concatenated_string', 'children': ['50', '51', '52']},{'id': '50', 'type': 'string', 'children': [], 'value': '"Your GSSAPI implementation does "'},{'id': '51', 'type': 'string', 'children': [], 'value': '"not have support for manipulating "'},{'id': '52', 'type': 'string', 'children': [], 'value': '"credential stores"'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_encode_dict'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'rcred_cred_store'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'acquire_cred_from'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69', '70', '71', '72']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'lifetime'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'mechs'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'tuples'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'AcquireCredResult'},{'id': '78', 'type': 'argument_list', 'children': ['79', '87', '90']},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'creds'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'mechs'},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'lifetime'}
def acquire(cls, name=None, lifetime=None, mechs=None, usage='both', store=None): if store is None: res = rcreds.acquire_cred(name, lifetime, mechs, usage) else: if rcred_cred_store is None: raise NotImplementedError("Your GSSAPI implementation does " "not have support for manipulating " "credential stores") store = _encode_dict(store) res = rcred_cred_store.acquire_cred_from(store, name, lifetime, mechs, usage) return tuples.AcquireCredResult(cls(base=res.creds), res.mechs, res.lifetime)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'store'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '10', 'type': 'string', 'children': [], 'value': "'both'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'mech'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'set_default'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'if_statement', 'children': ['22', '25', '49']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '38']},{'id': '26', 'type': 'if_statement', 'children': ['27', '30']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'rcred_rfc5588'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'raise_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'concatenated_string', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': '"Your GSSAPI implementation does "'},{'id': '37', 'type': 'string', 'children': [], 'value': '"not have support for RFC 5588"'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'rcred_rfc5588'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'store_cred'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45', '46', '47', '48']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'mech'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'set_default'},{'id': '49', 'type': 'else_clause', 'children': ['50']},{'id': '50', 'type': 'block', 'children': ['51', '64', '71']},{'id': '51', 'type': 'if_statement', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'rcred_cred_store'},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'raise_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'concatenated_string', 'children': ['61', '62', '63']},{'id': '61', 'type': 'string', 'children': [], 'value': '"Your GSSAPI implementation does "'},{'id': '62', 'type': 'string', 'children': [], 'value': '"not have support for manipulating "'},{'id': '63', 'type': 'string', 'children': [], 'value': '"credential stores directly"'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_encode_dict'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'rcred_cred_store'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'store_cred_into'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79', '80', '81', '82']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'mech'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'set_default'}
def store(self, store=None, usage='both', mech=None, overwrite=False, set_default=False): if store is None: if rcred_rfc5588 is None: raise NotImplementedError("Your GSSAPI implementation does " "not have support for RFC 5588") return rcred_rfc5588.store_cred(self, usage, mech, overwrite, set_default) else: if rcred_cred_store is None: raise NotImplementedError("Your GSSAPI implementation does " "not have support for manipulating " "credential stores directly") store = _encode_dict(store) return rcred_cred_store.store_cred_into(store, self, usage, mech, overwrite, set_default)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'mech'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '9', 'type': 'string', 'children': [], 'value': "'both'"},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'init_lifetime'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'accept_lifetime'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'impersonator'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '39', '127']},{'id': '23', 'type': 'if_statement', 'children': ['24', '31']},{'id': '24', 'type': 'boolean_operator', 'children': ['25', '28'], 'value': 'and'},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'impersonator'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'raise_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'concatenated_string', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'You cannot use both the `impersonator` and '"},{'id': '38', 'type': 'string', 'children': [], 'value': "'`store` arguments at the same time'"},{'id': '39', 'type': 'if_statement', 'children': ['40', '43', '79', '111']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'block', 'children': ['44', '57', '64']},{'id': '44', 'type': 'if_statement', 'children': ['45', '48']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'is'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'rcred_cred_store'},{'id': '47', 'type': 'None', 'children': []},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'concatenated_string', 'children': ['54', '55', '56']},{'id': '54', 'type': 'string', 'children': [], 'value': '"Your GSSAPI implementation does "'},{'id': '55', 'type': 'string', 'children': [], 'value': '"not have support for manipulating "'},{'id': '56', 'type': 'string', 'children': [], 'value': '"credential stores"'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_encode_dict'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'rcred_cred_store'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'add_cred_from'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73', '74', '75', '76', '77', '78']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'mech'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'init_lifetime'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'accept_lifetime'},{'id': '79', 'type': 'elif_clause', 'children': ['80', '83']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'is'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'impersonator'},{'id': '82', 'type': 'None', 'children': []},{'id': '83', 'type': 'block', 'children': ['84', '96']},{'id': '84', 'type': 'if_statement', 'children': ['85', '88']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'is'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'rcred_s4u'},{'id': '87', 'type': 'None', 'children': []},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'raise_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'concatenated_string', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': '"Your GSSAPI implementation does "'},{'id': '95', 'type': 'string', 'children': [], 'value': '"not have support for S4U"'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'rcred_s4u'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'add_cred_impersonate_name'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105', '106', '107', '108', '109', '110']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'impersonator'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'mech'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'init_lifetime'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'accept_lifetime'},{'id': '111', 'type': 'else_clause', 'children': ['112']},{'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': 'res'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'rcreds'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'add_cred'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122', '123', '124', '125', '126']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'mech'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'usage'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'init_lifetime'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'accept_lifetime'},{'id': '127', 'type': 'return_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'Credentials'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'creds'}
def add(self, name, mech, usage='both', init_lifetime=None, accept_lifetime=None, impersonator=None, store=None): if store is not None and impersonator is not None: raise ValueError('You cannot use both the `impersonator` and ' '`store` arguments at the same time') if store is not None: if rcred_cred_store is None: raise NotImplementedError("Your GSSAPI implementation does " "not have support for manipulating " "credential stores") store = _encode_dict(store) res = rcred_cred_store.add_cred_from(store, self, name, mech, usage, init_lifetime, accept_lifetime) elif impersonator is not None: if rcred_s4u is None: raise NotImplementedError("Your GSSAPI implementation does " "not have support for S4U") res = rcred_s4u.add_cred_impersonate_name(self, impersonator, name, mech, usage, init_lifetime, accept_lifetime) else: res = rcreds.add_cred(self, name, mech, usage, init_lifetime, accept_lifetime) return Credentials(res.creds)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '107']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'velocity_graph'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41', '44', '47', '50', '53', '56', '59', '62', '65', '68', '71', '74', '77', '80', '83', '86', '89', '92', '95', '98', '101', '104']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'vkey'},{'id': '10', 'type': 'string', 'children': [], 'value': "'velocity'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'which_graph'},{'id': '13', 'type': 'string', 'children': [], 'value': "'velocity'"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '16', 'type': 'integer', 'children': [], 'value': '10'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '19', 'type': 'float', 'children': [], 'value': '.8'},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'perc'},{'id': '22', 'type': 'integer', 'children': [], 'value': '90'},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'edge_width'},{'id': '25', 'type': 'float', 'children': [], 'value': '.2'},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'edge_color'},{'id': '28', 'type': 'string', 'children': [], 'value': "'grey'"},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'use_raw'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'color_map'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'default_parameter', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'colorbar'},{'id': '43', 'type': 'True', 'children': []},{'id': '44', 'type': 'default_parameter', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'default_parameter', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '49', 'type': 'None', 'children': []},{'id': '50', 'type': 'default_parameter', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '52', 'type': 'True', 'children': []},{'id': '53', 'type': 'default_parameter', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'default_parameter', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'default_parameter', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '61', 'type': 'string', 'children': [], 'value': "'2d'"},{'id': '62', 'type': 'default_parameter', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'legend_loc'},{'id': '64', 'type': 'string', 'children': [], 'value': "'on data'"},{'id': '65', 'type': 'default_parameter', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'legend_fontsize'},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'default_parameter', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'legend_fontweight'},{'id': '70', 'type': 'None', 'children': []},{'id': '71', 'type': 'default_parameter', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'right_margin'},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'default_parameter', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'left_margin'},{'id': '76', 'type': 'None', 'children': []},{'id': '77', 'type': 'default_parameter', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'xlabel'},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'default_parameter', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ylabel'},{'id': '82', 'type': 'None', 'children': []},{'id': '83', 'type': 'default_parameter', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '85', 'type': 'None', 'children': []},{'id': '86', 'type': 'default_parameter', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '88', 'type': 'None', 'children': []},{'id': '89', 'type': 'default_parameter', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '91', 'type': 'None', 'children': []},{'id': '92', 'type': 'default_parameter', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'dpi'},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'default_parameter', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'frameon'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'default_parameter', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '100', 'type': 'True', 'children': []},{'id': '101', 'type': 'default_parameter', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '103', 'type': 'None', 'children': []},{'id': '104', 'type': 'default_parameter', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '106', 'type': 'None', 'children': []},{'id': '107', 'type': 'block', 'children': ['108', '120', '131', '210', '234', '241', '312', '371', '390']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '111', 'type': 'conditional_expression', 'children': ['112', '116', '119'], 'value': 'if'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'default_basis'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'is'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '118', 'type': 'None', 'children': []},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '123', 'type': 'conditional_expression', 'children': ['124', '127', '130'], 'value': 'if'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '+'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'which_graph'},{'id': '126', 'type': 'string', 'children': [], 'value': "' graph'"},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'scatter_kwargs'},{'id': '134', 'type': 'dictionary', 'children': ['135', '138', '141', '144', '147', '150', '153', '156', '159', '162', '165', '168', '171', '174', '177', '180', '183', '186', '189', '192', '195', '198', '201', '204', '207']},{'id': '135', 'type': 'pair', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': '"basis"'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '138', 'type': 'pair', 'children': ['139', '140']},{'id': '139', 'type': 'string', 'children': [], 'value': '"perc"'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'perc'},{'id': '141', 'type': 'pair', 'children': ['142', '143']},{'id': '142', 'type': 'string', 'children': [], 'value': '"use_raw"'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'use_raw'},{'id': '144', 'type': 'pair', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': '"sort_order"'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '147', 'type': 'pair', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': '"alpha"'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '150', 'type': 'pair', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': '"components"'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '153', 'type': 'pair', 'children': ['154', '155']},{'id': '154', 'type': 'string', 'children': [], 'value': '"projection"'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '156', 'type': 'pair', 'children': ['157', '158']},{'id': '157', 'type': 'string', 'children': [], 'value': '"legend_loc"'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'legend_loc'},{'id': '159', 'type': 'pair', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': '"groups"'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '162', 'type': 'pair', 'children': ['163', '164']},{'id': '163', 'type': 'string', 'children': [], 'value': '"legend_fontsize"'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'legend_fontsize'},{'id': '165', 'type': 'pair', 'children': ['166', '167']},{'id': '166', 'type': 'string', 'children': [], 'value': '"legend_fontweight"'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'legend_fontweight'},{'id': '168', 'type': 'pair', 'children': ['169', '170']},{'id': '169', 'type': 'string', 'children': [], 'value': '"palette"'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'palette'},{'id': '171', 'type': 'pair', 'children': ['172', '173']},{'id': '172', 'type': 'string', 'children': [], 'value': '"color_map"'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'color_map'},{'id': '174', 'type': 'pair', 'children': ['175', '176']},{'id': '175', 'type': 'string', 'children': [], 'value': '"frameon"'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'frameon'},{'id': '177', 'type': 'pair', 'children': ['178', '179']},{'id': '178', 'type': 'string', 'children': [], 'value': '"title"'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '180', 'type': 'pair', 'children': ['181', '182']},{'id': '181', 'type': 'string', 'children': [], 'value': '"xlabel"'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'xlabel'},{'id': '183', 'type': 'pair', 'children': ['184', '185']},{'id': '184', 'type': 'string', 'children': [], 'value': '"ylabel"'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'ylabel'},{'id': '186', 'type': 'pair', 'children': ['187', '188']},{'id': '187', 'type': 'string', 'children': [], 'value': '"right_margin"'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'right_margin'},{'id': '189', 'type': 'pair', 'children': ['190', '191']},{'id': '190', 'type': 'string', 'children': [], 'value': '"left_margin"'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'left_margin'},{'id': '192', 'type': 'pair', 'children': ['193', '194']},{'id': '193', 'type': 'string', 'children': [], 'value': '"colorbar"'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'colorbar'},{'id': '195', 'type': 'pair', 'children': ['196', '197']},{'id': '196', 'type': 'string', 'children': [], 'value': '"dpi"'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'dpi'},{'id': '198', 'type': 'pair', 'children': ['199', '200']},{'id': '199', 'type': 'string', 'children': [], 'value': '"fontsize"'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '201', 'type': 'pair', 'children': ['202', '203']},{'id': '202', 'type': 'string', 'children': [], 'value': '"show"'},{'id': '203', 'type': 'False', 'children': []},{'id': '204', 'type': 'pair', 'children': ['205', '206']},{'id': '205', 'type': 'string', 'children': [], 'value': '"save"'},{'id': '206', 'type': 'None', 'children': []},{'id': '207', 'type': 'pair', 'children': ['208', '209']},{'id': '208', 'type': 'string', 'children': [], 'value': '"figsize"'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'scatter'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217', '220', '223', '226', '229', '232']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '220', 'type': 'keyword_argument', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '223', 'type': 'keyword_argument', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '226', 'type': 'keyword_argument', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '229', 'type': 'keyword_argument', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'zorder'},{'id': '231', 'type': 'integer', 'children': [], 'value': '0'},{'id': '232', 'type': 'dictionary_splat', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'scatter_kwargs'},{'id': '234', 'type': 'import_from_statement', 'children': ['235', '237', '239']},{'id': '235', 'type': 'dotted_name', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'networkx'},{'id': '237', 'type': 'dotted_name', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'Graph'},{'id': '239', 'type': 'dotted_name', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'draw_networkx_edges'},{'id': '241', 'type': 'if_statement', 'children': ['242', '245', '291']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': '=='},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'which_graph'},{'id': '244', 'type': 'string', 'children': [], 'value': "'neighbors'"},{'id': '245', 'type': 'block', 'children': ['246', '256']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '249', 'type': 'subscript', 'children': ['250', '255']},{'id': '250', 'type': 'subscript', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '254', 'type': 'string', 'children': [], 'value': "'neighbors'"},{'id': '255', 'type': 'string', 'children': [], 'value': "'connectivities'"},{'id': '256', 'type': 'if_statement', 'children': ['257', '260']},{'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': 'is'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'perc'},{'id': '259', 'type': 'None', 'children': []},{'id': '260', 'type': 'block', 'children': ['261', '273', '285']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'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': 'percentile'},{'id': '268', 'type': 'argument_list', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'perc'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '284']},{'id': '275', 'type': 'subscript', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '279', 'type': 'comparison_operator', 'children': ['280', '283'], 'value': '<'},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '284', 'type': 'integer', 'children': [], 'value': '0'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'eliminate_zeros'},{'id': '290', 'type': 'argument_list', 'children': []},{'id': '291', 'type': 'else_clause', 'children': ['292']},{'id': '292', 'type': 'block', 'children': ['293']},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'assignment', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'transition_matrix'},{'id': '298', 'type': 'argument_list', 'children': ['299', '300', '303', '306', '309']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '300', 'type': 'keyword_argument', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'vkey'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'vkey'},{'id': '303', 'type': 'keyword_argument', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'weight_indirect_neighbors'},{'id': '305', 'type': 'integer', 'children': [], 'value': '0'},{'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '309', 'type': 'keyword_argument', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'perc'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'perc'},{'id': '312', 'type': 'with_statement', 'children': ['313', '320']},{'id': '313', 'type': 'with_clause', 'children': ['314']},{'id': '314', 'type': 'with_item', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'catch_warnings'},{'id': '319', 'type': 'argument_list', 'children': []},{'id': '320', 'type': 'block', 'children': ['321', '328', '354', '362']},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'simplefilter'},{'id': '326', 'type': 'argument_list', 'children': ['327']},{'id': '327', 'type': 'string', 'children': [], 'value': '"ignore"'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '331', 'type': 'call', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'draw_networkx_edges'},{'id': '333', 'type': 'argument_list', 'children': ['334', '338', '345', '348', '351']},{'id': '334', 'type': 'call', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'Graph'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '338', 'type': 'subscript', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'obsm'},{'id': '342', 'type': 'binary_operator', 'children': ['343', '344'], 'value': '+'},{'id': '343', 'type': 'string', 'children': [], 'value': "'X_'"},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '345', 'type': 'keyword_argument', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'edge_width'},{'id': '348', 'type': 'keyword_argument', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'edge_color'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'edge_color'},{'id': '351', 'type': 'keyword_argument', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'call', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'set_zorder'},{'id': '359', 'type': 'argument_list', 'children': ['360']},{'id': '360', 'type': 'unary_operator', 'children': ['361'], 'value': '-'},{'id': '361', 'type': 'integer', 'children': [], 'value': '2'},{'id': '362', 'type': 'expression_statement', 'children': ['363']},{'id': '363', 'type': 'call', 'children': ['364', '367']},{'id': '364', 'type': 'attribute', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'set_rasterized'},{'id': '367', 'type': 'argument_list', 'children': ['368']},{'id': '368', 'type': 'attribute', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '370', 'type': 'identifier', 'children': [], 'value': '_vector_friendly'},{'id': '371', 'type': 'expression_statement', 'children': ['372']},{'id': '372', 'type': 'call', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'savefig_or_show'},{'id': '374', 'type': 'argument_list', 'children': ['375', '381', '384', '387']},{'id': '375', 'type': 'conditional_expression', 'children': ['376', '377', '380'], 'value': 'if'},{'id': '376', 'type': 'string', 'children': [], 'value': "''"},{'id': '377', 'type': 'comparison_operator', 'children': ['378', '379'], 'value': 'is'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '379', 'type': 'None', 'children': []},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '381', 'type': 'keyword_argument', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'dpi'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'dpi'},{'id': '384', 'type': 'keyword_argument', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '387', 'type': 'keyword_argument', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '390', 'type': 'if_statement', 'children': ['391', '393']},{'id': '391', 'type': 'not_operator', 'children': ['392']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '393', 'type': 'block', 'children': ['394']},{'id': '394', 'type': 'return_statement', 'children': ['395']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'ax'}
def velocity_graph(adata, basis=None, vkey='velocity', which_graph='velocity', n_neighbors=10, alpha=.8, perc=90, edge_width=.2, edge_color='grey', color=None, use_raw=None, layer=None, color_map=None, colorbar=True, palette=None, size=None, sort_order=True, groups=None, components=None, projection='2d', legend_loc='on data', legend_fontsize=None, legend_fontweight=None, right_margin=None, left_margin=None, xlabel=None, ylabel=None, title=None, fontsize=None, figsize=None, dpi=None, frameon=None, show=True, save=None, ax=None): basis = default_basis(adata) if basis is None else basis title = which_graph + ' graph' if title is None else title scatter_kwargs = {"basis": basis, "perc": perc, "use_raw": use_raw, "sort_order": sort_order, "alpha": alpha, "components": components, "projection": projection, "legend_loc": legend_loc, "groups": groups, "legend_fontsize": legend_fontsize, "legend_fontweight": legend_fontweight, "palette": palette, "color_map": color_map, "frameon": frameon, "title": title, "xlabel": xlabel, "ylabel": ylabel, "right_margin": right_margin, "left_margin": left_margin, "colorbar": colorbar, "dpi": dpi, "fontsize": fontsize, "show": False, "save": None, "figsize": figsize, } ax = scatter(adata, layer=layer, color=color, size=size, ax=ax, zorder=0, **scatter_kwargs) from networkx import Graph, draw_networkx_edges if which_graph == 'neighbors': T = adata.uns['neighbors']['connectivities'] if perc is not None: threshold = np.percentile(T.data, perc) T.data[T.data < threshold] = 0 T.eliminate_zeros() else: T = transition_matrix(adata, vkey=vkey, weight_indirect_neighbors=0, n_neighbors=n_neighbors, perc=perc) with warnings.catch_warnings(): warnings.simplefilter("ignore") edges = draw_networkx_edges(Graph(T), adata.obsm['X_' + basis], width=edge_width, edge_color=edge_color, ax=ax) edges.set_zorder(-2) edges.set_rasterized(settings._vector_friendly) savefig_or_show('' if basis is None else basis, dpi=dpi, save=save, show=show) if not show: return ax
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cleanup'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'clean'},{'id': '7', 'type': 'string', 'children': [], 'value': "'layers'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '26', '51', '64', '101', '126', '154']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '18', 'type': 'conditional_expression', 'children': ['19', '24', '25'], 'value': 'if'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '29', 'type': 'conditional_expression', 'children': ['30', '35', '40'], 'value': 'if'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'list', 'children': ['34'], 'value': '[keep]'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '40', 'type': 'conditional_expression', 'children': ['41', '44', '47'], 'value': 'if'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'keep'},{'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': 'keep'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'list', 'children': ['58', '59', '60', '61', '62', '63'], 'value': "['spliced', 'unspliced', 'Ms', 'Mu', 'clusters', 'neighbors']"},{'id': '58', 'type': 'string', 'children': [], 'value': "'spliced'"},{'id': '59', 'type': 'string', 'children': [], 'value': "'unspliced'"},{'id': '60', 'type': 'string', 'children': [], 'value': "'Ms'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'Mu'"},{'id': '62', 'type': 'string', 'children': [], 'value': "'clusters'"},{'id': '63', 'type': 'string', 'children': [], 'value': "'neighbors'"},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ann_dict'},{'id': '67', 'type': 'dictionary', 'children': ['68', '75', '82', '89']},{'id': '68', 'type': 'pair', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': "'obs'"},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'obs_keys'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'pair', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': "'var'"},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'var_keys'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'pair', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "'uns'"},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'uns_keys'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'pair', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': "'layers'"},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'if_statement', 'children': ['102', '105']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'not'},{'id': '103', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'clean'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'ann_dict'},{'id': '109', 'type': 'dictionary_comprehension', 'children': ['110', '113', '122']},{'id': '110', 'type': 'pair', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '113', 'type': 'for_in_clause', 'children': ['114', '117']},{'id': '114', 'type': 'tuple_pattern', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ann_dict'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'if_clause', 'children': ['123']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'in'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'clean'},{'id': '126', 'type': 'for_statement', 'children': ['127', '130', '135']},{'id': '127', 'type': 'tuple_pattern', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ann_dict'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '134', 'type': 'argument_list', 'children': []},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'for_statement', 'children': ['137', '138', '139']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'if_statement', 'children': ['141', '144']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': 'not'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'delete_statement', 'children': ['146']},{'id': '146', 'type': '()', 'children': ['147']},{'id': '147', 'type': 'subscript', 'children': ['148', '153']},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '154', 'type': 'return_statement', 'children': ['155']},{'id': '155', 'type': 'conditional_expression', 'children': ['156', '157', '158'], 'value': 'if'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '158', 'type': 'None', 'children': []}
def cleanup(data, clean='layers', keep=None, copy=False): adata = data.copy() if copy else data keep = list([keep]) if isinstance(keep, str) else list() if keep is None else list(keep) keep.extend(['spliced', 'unspliced', 'Ms', 'Mu', 'clusters', 'neighbors']) ann_dict = {'obs': adata.obs_keys(), 'var': adata.var_keys(), 'uns': adata.uns_keys(), 'layers': list(adata.layers.keys())} if 'all' not in clean: ann_dict = {ann: values for (ann, values) in ann_dict.items() if ann in clean} for (ann, values) in ann_dict.items(): for value in values: if value not in keep: del(getattr(adata, ann)[value]) return adata if copy else None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '38']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_genes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'min_counts'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'min_cells'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'max_counts'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'max_cells'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'min_counts_u'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'min_cells_u'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'max_counts_u'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'max_cells_u'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'min_shared_counts'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'min_shared_cells'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '37', 'type': 'False', 'children': []},{'id': '38', 'type': 'block', 'children': ['39', '50', '55', '75', '92', '440']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '42', 'type': 'conditional_expression', 'children': ['43', '48', '49'], 'value': 'if'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'set_initial_size'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '58', 'type': 'list_comprehension', 'children': ['59', '60', '65']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '62', 'type': 'list', 'children': ['63', '64'], 'value': "['spliced', 'unspliced']"},{'id': '63', 'type': 'string', 'children': [], 'value': "'spliced'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'unspliced'"},{'id': '65', 'type': 'if_clause', 'children': ['66']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'in'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'layer'},{'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': 'adata'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'if_statement', 'children': ['76', '83']},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '80'], 'value': 'or'},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'is'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'min_shared_counts'},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'is'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'min_shared_cells'},{'id': '82', 'type': 'None', 'children': []},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'list', 'children': ['91'], 'value': "['shared']"},{'id': '91', 'type': 'string', 'children': [], 'value': "'shared'"},{'id': '92', 'type': 'for_statement', 'children': ['93', '94', '95']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '95', 'type': 'block', 'children': ['96', '144', '236', '250', '281', '312', '322']},{'id': '96', 'type': 'if_statement', 'children': ['97', '100', '113', '130']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'is'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '99', 'type': 'string', 'children': [], 'value': "'spliced'"},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '108']},{'id': '103', 'type': 'pattern_list', 'children': ['104', '105', '106', '107']},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_min_counts'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_min_cells'},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_max_counts'},{'id': '107', 'type': 'identifier', 'children': [], 'value': '_max_cells'},{'id': '108', 'type': 'expression_list', 'children': ['109', '110', '111', '112']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'min_counts'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'min_cells'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'max_counts'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'max_cells'},{'id': '113', 'type': 'elif_clause', 'children': ['114', '117']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'is'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '116', 'type': 'string', 'children': [], 'value': "'unspliced'"},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '125']},{'id': '120', 'type': 'pattern_list', 'children': ['121', '122', '123', '124']},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_min_counts'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_min_cells'},{'id': '123', 'type': 'identifier', 'children': [], 'value': '_max_counts'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_max_cells'},{'id': '125', 'type': 'expression_list', 'children': ['126', '127', '128', '129']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'min_counts_u'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'min_cells_u'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'max_counts_u'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'max_cells_u'},{'id': '130', 'type': 'else_clause', 'children': ['131']},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '139']},{'id': '134', 'type': 'pattern_list', 'children': ['135', '136', '137', '138']},{'id': '135', 'type': 'identifier', 'children': [], 'value': '_min_counts'},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_min_cells'},{'id': '137', 'type': 'identifier', 'children': [], 'value': '_max_counts'},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_max_cells'},{'id': '139', 'type': 'expression_list', 'children': ['140', '141', '142', '143']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'min_shared_counts'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'min_shared_cells'},{'id': '142', 'type': 'None', 'children': []},{'id': '143', 'type': 'None', 'children': []},{'id': '144', 'type': 'if_statement', 'children': ['145', '154', '163']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'in'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'layer'},{'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': 'adata'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '158', 'type': 'subscript', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '163', 'type': 'else_clause', 'children': ['164']},{'id': '164', 'type': 'block', 'children': ['165', '181', '209']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '170']},{'id': '167', 'type': 'pattern_list', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'Xu'},{'id': '170', 'type': 'expression_list', 'children': ['171', '176']},{'id': '171', 'type': 'subscript', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '175', 'type': 'string', 'children': [], 'value': "'spliced'"},{'id': '176', 'type': 'subscript', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '180', 'type': 'string', 'children': [], 'value': "'unspliced'"},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'nonzeros'},{'id': '184', 'type': 'conditional_expression', 'children': ['185', '196', '200'], 'value': 'if'},{'id': '185', 'type': 'call', 'children': ['186', '192']},{'id': '186', 'type': 'attribute', 'children': ['187', '191']},{'id': '187', 'type': '()', 'children': ['188']},{'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': '>'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'id': '190', 'type': 'integer', 'children': [], 'value': '0'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'multiply'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': '>'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'Xu'},{'id': '195', 'type': 'integer', 'children': [], 'value': '0'},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'issparse'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'id': '200', 'type': 'binary_operator', 'children': ['201', '205'], 'value': '*'},{'id': '201', 'type': '()', 'children': ['202']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': '>'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'id': '204', 'type': 'integer', 'children': [], 'value': '0'},{'id': '205', 'type': '()', 'children': ['206']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': '>'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'Xu'},{'id': '208', 'type': 'integer', 'children': [], 'value': '0'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '212', 'type': 'conditional_expression', 'children': ['213', '226', '230'], 'value': 'if'},{'id': '213', 'type': 'binary_operator', 'children': ['214', '220'], 'value': '+'},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'nonzeros'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'multiply'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'nonzeros'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'multiply'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'Xu'},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'issparse'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'nonzeros'},{'id': '230', 'type': 'binary_operator', 'children': ['231', '232'], 'value': '*'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'nonzeros'},{'id': '232', 'type': '()', 'children': ['233']},{'id': '233', 'type': 'binary_operator', 'children': ['234', '235'], 'value': '+'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'Xs'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'Xu'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'gene_subset'},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'ones'},{'id': '243', 'type': 'argument_list', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'n_vars'},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '250', 'type': 'if_statement', 'children': ['251', '258']},{'id': '251', 'type': 'boolean_operator', 'children': ['252', '255'], 'value': 'or'},{'id': '252', 'type': 'comparison_operator', 'children': ['253', '254'], 'value': 'is'},{'id': '253', 'type': 'identifier', 'children': [], 'value': '_min_counts'},{'id': '254', 'type': 'None', 'children': []},{'id': '255', 'type': 'comparison_operator', 'children': ['256', '257'], 'value': 'is'},{'id': '256', 'type': 'identifier', 'children': [], 'value': '_max_counts'},{'id': '257', 'type': 'None', 'children': []},{'id': '258', 'type': 'block', 'children': ['259', '274']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '264']},{'id': '261', 'type': 'pattern_list', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'gene_subset'},{'id': '263', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '264', 'type': 'call', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '266', 'type': 'argument_list', 'children': ['267', '268', '271']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'min_counts'},{'id': '270', 'type': 'identifier', 'children': [], 'value': '_min_counts'},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'max_counts'},{'id': '273', 'type': 'identifier', 'children': [], 'value': '_max_counts'},{'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': 'adata'},{'id': '278', 'type': 'identifier', 'children': [], 'value': '_inplace_subset_var'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'gene_subset'},{'id': '281', 'type': 'if_statement', 'children': ['282', '289']},{'id': '282', 'type': 'boolean_operator', 'children': ['283', '286'], 'value': 'or'},{'id': '283', 'type': 'comparison_operator', 'children': ['284', '285'], 'value': 'is'},{'id': '284', 'type': 'identifier', 'children': [], 'value': '_min_cells'},{'id': '285', 'type': 'None', 'children': []},{'id': '286', 'type': 'comparison_operator', 'children': ['287', '288'], 'value': 'is'},{'id': '287', 'type': 'identifier', 'children': [], 'value': '_max_cells'},{'id': '288', 'type': 'None', 'children': []},{'id': '289', 'type': 'block', 'children': ['290', '305']},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'assignment', 'children': ['292', '295']},{'id': '292', 'type': 'pattern_list', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'gene_subset'},{'id': '294', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '295', 'type': 'call', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '297', 'type': 'argument_list', 'children': ['298', '299', '302']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'min_cells'},{'id': '301', 'type': 'identifier', 'children': [], 'value': '_min_cells'},{'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'max_cells'},{'id': '304', 'type': 'identifier', 'children': [], 'value': '_max_cells'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '309', 'type': 'identifier', 'children': [], 'value': '_inplace_subset_var'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'gene_subset'},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'unary_operator', 'children': ['321'], 'value': '~'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'gene_subset'},{'id': '322', 'type': 'if_statement', 'children': ['323', '326']},{'id': '323', 'type': 'comparison_operator', 'children': ['324', '325'], 'value': '>'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '325', 'type': 'integer', 'children': [], 'value': '0'},{'id': '326', 'type': 'block', 'children': ['327', '342', '391']},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'call', 'children': ['329', '332']},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'logg'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '332', 'type': 'argument_list', 'children': ['333', '339']},{'id': '333', 'type': 'call', 'children': ['334', '337']},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'string', 'children': [], 'value': "'Filtered out {} genes that are detected'"},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '337', 'type': 'argument_list', 'children': ['338']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '339', 'type': 'keyword_argument', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '341', 'type': 'string', 'children': [], 'value': "' '"},{'id': '342', 'type': 'if_statement', 'children': ['343', '350']},{'id': '343', 'type': 'boolean_operator', 'children': ['344', '347'], 'value': 'or'},{'id': '344', 'type': 'comparison_operator', 'children': ['345', '346'], 'value': 'is'},{'id': '345', 'type': 'identifier', 'children': [], 'value': '_min_cells'},{'id': '346', 'type': 'None', 'children': []},{'id': '347', 'type': 'comparison_operator', 'children': ['348', '349'], 'value': 'is'},{'id': '348', 'type': 'identifier', 'children': [], 'value': '_min_counts'},{'id': '349', 'type': 'None', 'children': []},{'id': '350', 'type': 'block', 'children': ['351']},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'logg'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '356', 'type': 'argument_list', 'children': ['357', '358', '388']},{'id': '357', 'type': 'string', 'children': [], 'value': "'in less than'"},{'id': '358', 'type': 'conditional_expression', 'children': ['359', '372', '375'], 'value': 'if'},{'id': '359', 'type': 'binary_operator', 'children': ['360', '371'], 'value': '+'},{'id': '360', 'type': 'binary_operator', 'children': ['361', '367'], 'value': '+'},{'id': '361', 'type': 'binary_operator', 'children': ['362', '366'], 'value': '+'},{'id': '362', 'type': 'call', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'identifier', 'children': [], 'value': '_min_cells'},{'id': '366', 'type': 'string', 'children': [], 'value': "' cells ('"},{'id': '367', 'type': 'call', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '371', 'type': 'string', 'children': [], 'value': "').'"},{'id': '372', 'type': 'comparison_operator', 'children': ['373', '374'], 'value': 'is'},{'id': '373', 'type': 'identifier', 'children': [], 'value': '_min_counts'},{'id': '374', 'type': 'None', 'children': []},{'id': '375', 'type': 'binary_operator', 'children': ['376', '387'], 'value': '+'},{'id': '376', 'type': 'binary_operator', 'children': ['377', '383'], 'value': '+'},{'id': '377', 'type': 'binary_operator', 'children': ['378', '382'], 'value': '+'},{'id': '378', 'type': 'call', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'identifier', 'children': [], 'value': '_min_counts'},{'id': '382', 'type': 'string', 'children': [], 'value': "' counts ('"},{'id': '383', 'type': 'call', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '387', 'type': 'string', 'children': [], 'value': "').'"},{'id': '388', 'type': 'keyword_argument', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'no_indent'},{'id': '390', 'type': 'True', 'children': []},{'id': '391', 'type': 'if_statement', 'children': ['392', '399']},{'id': '392', 'type': 'boolean_operator', 'children': ['393', '396'], 'value': 'or'},{'id': '393', 'type': 'comparison_operator', 'children': ['394', '395'], 'value': 'is'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'max_cells'},{'id': '395', 'type': 'None', 'children': []},{'id': '396', 'type': 'comparison_operator', 'children': ['397', '398'], 'value': 'is'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'max_counts'},{'id': '398', 'type': 'None', 'children': []},{'id': '399', 'type': 'block', 'children': ['400']},{'id': '400', 'type': 'expression_statement', 'children': ['401']},{'id': '401', 'type': 'call', 'children': ['402', '405']},{'id': '402', 'type': 'attribute', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'logg'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '405', 'type': 'argument_list', 'children': ['406', '407', '437']},{'id': '406', 'type': 'string', 'children': [], 'value': "'in more than '"},{'id': '407', 'type': 'conditional_expression', 'children': ['408', '421', '424'], 'value': 'if'},{'id': '408', 'type': 'binary_operator', 'children': ['409', '420'], 'value': '+'},{'id': '409', 'type': 'binary_operator', 'children': ['410', '416'], 'value': '+'},{'id': '410', 'type': 'binary_operator', 'children': ['411', '415'], 'value': '+'},{'id': '411', 'type': 'call', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '413', 'type': 'argument_list', 'children': ['414']},{'id': '414', 'type': 'identifier', 'children': [], 'value': '_max_cells'},{'id': '415', 'type': 'string', 'children': [], 'value': "' cells('"},{'id': '416', 'type': 'call', 'children': ['417', '418']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '418', 'type': 'argument_list', 'children': ['419']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '420', 'type': 'string', 'children': [], 'value': "').'"},{'id': '421', 'type': 'comparison_operator', 'children': ['422', '423'], 'value': 'is'},{'id': '422', 'type': 'identifier', 'children': [], 'value': '_max_counts'},{'id': '423', 'type': 'None', 'children': []},{'id': '424', 'type': 'binary_operator', 'children': ['425', '436'], 'value': '+'},{'id': '425', 'type': 'binary_operator', 'children': ['426', '432'], 'value': '+'},{'id': '426', 'type': 'binary_operator', 'children': ['427', '431'], 'value': '+'},{'id': '427', 'type': 'call', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '429', 'type': 'argument_list', 'children': ['430']},{'id': '430', 'type': 'identifier', 'children': [], 'value': '_max_counts'},{'id': '431', 'type': 'string', 'children': [], 'value': "' counts ('"},{'id': '432', 'type': 'call', 'children': ['433', '434']},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '434', 'type': 'argument_list', 'children': ['435']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '436', 'type': 'string', 'children': [], 'value': "').'"},{'id': '437', 'type': 'keyword_argument', 'children': ['438', '439']},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'no_indent'},{'id': '439', 'type': 'True', 'children': []},{'id': '440', 'type': 'return_statement', 'children': ['441']},{'id': '441', 'type': 'conditional_expression', 'children': ['442', '443', '444'], 'value': 'if'},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '444', 'type': 'None', 'children': []}
def filter_genes(data, min_counts=None, min_cells=None, max_counts=None, max_cells=None, min_counts_u=None, min_cells_u=None, max_counts_u=None, max_cells_u=None, min_shared_counts=None, min_shared_cells=None, copy=False): adata = data.copy() if copy else data set_initial_size(adata) layers = [layer for layer in ['spliced', 'unspliced'] if layer in adata.layers.keys()] if min_shared_counts is not None or min_shared_cells is not None: layers.extend(['shared']) for layer in layers: if layer is 'spliced': _min_counts, _min_cells, _max_counts, _max_cells = min_counts, min_cells, max_counts, max_cells elif layer is 'unspliced': _min_counts, _min_cells, _max_counts, _max_cells = min_counts_u, min_cells_u, max_counts_u, max_cells_u else: _min_counts, _min_cells, _max_counts, _max_cells = min_shared_counts, min_shared_cells, None, None if layer in adata.layers.keys(): X = adata.layers[layer] else: Xs, Xu = adata.layers['spliced'], adata.layers['unspliced'] nonzeros = (Xs > 0).multiply(Xu > 0) if issparse(Xs) else (Xs > 0) * (Xu > 0) X = nonzeros.multiply(Xs) + nonzeros.multiply(Xu) if issparse(nonzeros) else nonzeros * (Xs + Xu) gene_subset = np.ones(adata.n_vars, dtype=bool) if _min_counts is not None or _max_counts is not None: gene_subset, _ = filter(X, min_counts=_min_counts, max_counts=_max_counts) adata._inplace_subset_var(gene_subset) if _min_cells is not None or _max_cells is not None: gene_subset, _ = filter(X, min_cells=_min_cells, max_cells=_max_cells) adata._inplace_subset_var(gene_subset) s = np.sum(~gene_subset) if s > 0: logg.info('Filtered out {} genes that are detected'.format(s), end=' ') if _min_cells is not None or _min_counts is not None: logg.info('in less than', str(_min_cells) + ' cells (' + str(layer) + ').' if _min_counts is None else str(_min_counts) + ' counts (' + str(layer) + ').', no_indent=True) if max_cells is not None or max_counts is not None: logg.info('in more than ', str(_max_cells) + ' cells(' + str(layer) + ').' if _max_counts is None else str(_max_counts) + ' counts (' + str(layer) + ').', no_indent=True) return adata if copy else None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_genes_dispersion'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '7', 'type': 'string', 'children': [], 'value': "'seurat'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'min_disp'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'max_disp'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'min_mean'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'max_mean'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '22', 'type': 'integer', 'children': [], 'value': '20'},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'n_top_genes'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '28', 'type': 'True', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'block', 'children': ['33', '44', '49', '277']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '36', 'type': 'conditional_expression', 'children': ['37', '42', '43'], 'value': 'if'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'set_initial_size'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '49', 'type': 'if_statement', 'children': ['50', '59', '67']},{'id': '50', 'type': 'boolean_operator', 'children': ['51', '54'], 'value': 'and'},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'n_top_genes'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': '<'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'n_vars'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'n_top_genes'},{'id': '59', 'type': 'block', 'children': ['60']},{'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': 'logg'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'string', 'children': [], 'value': "'Skip filtering by dispersion since number of variables are less than `n_top_genes`'"},{'id': '67', 'type': 'else_clause', 'children': ['68']},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'if_statement', 'children': ['70', '73', '239']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '72', 'type': 'string', 'children': [], 'value': "'svr'"},{'id': '73', 'type': 'block', 'children': ['74', '102', '146', '155', '166', '172', '186', '198', '213', '230']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '77', 'type': 'conditional_expression', 'children': ['78', '88', '94'], 'value': 'if'},{'id': '78', 'type': 'attribute', 'children': ['79', '87']},{'id': '79', 'type': 'call', 'children': ['80', '85']},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'integer', 'children': [], 'value': '0'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'A1'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'issparse'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'integer', 'children': [], 'value': '0'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '105', 'type': 'conditional_expression', 'children': ['106', '132', '138'], 'value': 'if'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'binary_operator', 'children': ['112', '129'], 'value': '-'},{'id': '112', 'type': 'attribute', 'children': ['113', '128']},{'id': '113', 'type': 'call', 'children': ['114', '126']},{'id': '114', 'type': 'attribute', 'children': ['115', '125']},{'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': 'adata'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'multiply'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'A1'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '**'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '131', 'type': 'integer', 'children': [], 'value': '2'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'issparse'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '138', 'type': 'call', 'children': ['139', '144']},{'id': '139', 'type': 'attribute', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'std'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'log_mu'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'log2'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'log_cv'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'log2'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '/'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '166', 'type': 'import_from_statement', 'children': ['167', '170']},{'id': '167', 'type': 'dotted_name', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'sklearn'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'svm'},{'id': '170', 'type': 'dotted_name', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'SVR'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'clf'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'SVR'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'gamma'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '/'},{'id': '181', 'type': 'float', 'children': [], 'value': '150.'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'clf'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'fit'},{'id': '191', 'type': 'argument_list', 'children': ['192', '197']},{'id': '192', 'type': 'subscript', 'children': ['193', '194', '196']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'log_mu'},{'id': '194', 'type': 'slice', 'children': ['195']},{'id': '195', 'type': 'colon', 'children': []},{'id': '196', 'type': 'None', 'children': []},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'log_cv'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '-'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'log_cv'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'clf'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'predict'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'subscript', 'children': ['209', '210', '212']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'log_mu'},{'id': '210', 'type': 'slice', 'children': ['211']},{'id': '211', 'type': 'colon', 'children': []},{'id': '212', 'type': 'None', 'children': []},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'nth_score'},{'id': '216', 'type': 'subscript', 'children': ['217', '229']},{'id': '217', 'type': 'subscript', 'children': ['218', '224']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '224', 'type': 'slice', 'children': ['225', '226', '227']},{'id': '225', 'type': 'colon', 'children': []},{'id': '226', 'type': 'colon', 'children': []},{'id': '227', 'type': 'unary_operator', 'children': ['228'], 'value': '-'},{'id': '228', 'type': 'integer', 'children': [], 'value': '1'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'n_top_genes'},{'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': 'adata'},{'id': '234', 'type': 'identifier', 'children': [], 'value': '_inplace_subset_var'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': '>='},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'nth_score'},{'id': '239', 'type': 'else_clause', 'children': ['240']},{'id': '240', 'type': 'block', 'children': ['241', '248']},{'id': '241', 'type': 'import_from_statement', 'children': ['242', '246']},{'id': '242', 'type': 'dotted_name', 'children': ['243', '244', '245']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'scanpy'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'pp'},{'id': '246', 'type': 'dotted_name', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'filter_genes_dispersion'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'filter_genes_dispersion'},{'id': '251', 'type': 'argument_list', 'children': ['252', '253', '256', '259', '262', '265', '268', '271', '274']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '256', 'type': 'keyword_argument', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'min_disp'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'min_disp'},{'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'max_disp'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'max_disp'},{'id': '262', 'type': 'keyword_argument', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'min_mean'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'min_mean'},{'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'max_mean'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'max_mean'},{'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'n_bins'},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'n_top_genes'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'n_top_genes'},{'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '277', 'type': 'return_statement', 'children': ['278']},{'id': '278', 'type': 'conditional_expression', 'children': ['279', '280', '281'], 'value': 'if'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '281', 'type': 'None', 'children': []}
def filter_genes_dispersion(data, flavor='seurat', min_disp=None, max_disp=None, min_mean=None, max_mean=None, n_bins=20, n_top_genes=None, log=True, copy=False): adata = data.copy() if copy else data set_initial_size(adata) if n_top_genes is not None and adata.n_vars < n_top_genes: logg.info('Skip filtering by dispersion since number of variables are less than `n_top_genes`') else: if flavor is 'svr': mu = adata.X.mean(0).A1 if issparse(adata.X) else adata.X.mean(0) sigma = np.sqrt(adata.X.multiply(adata.X).mean(0).A1 - mu ** 2) if issparse(adata.X) else adata.X.std(0) log_mu = np.log2(mu) log_cv = np.log2(sigma / mu) from sklearn.svm import SVR clf = SVR(gamma=150. / len(mu)) clf.fit(log_mu[:, None], log_cv) score = log_cv - clf.predict(log_mu[:, None]) nth_score = np.sort(score)[::-1][n_top_genes] adata._inplace_subset_var(score >= nth_score) else: from scanpy.api.pp import filter_genes_dispersion filter_genes_dispersion(adata, flavor=flavor, min_disp=min_disp, max_disp=max_disp, min_mean=min_mean, max_mean=max_mean, n_bins=n_bins, n_top_genes=n_top_genes, log=log) return adata if copy else None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'normalize_per_cell'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '25', '28']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'counts_per_cell_after'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'counts_per_cell'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'key_n_counts'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'max_proportion_per_cell'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'use_initial_size'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '22', 'type': 'list', 'children': ['23', '24'], 'value': "['spliced', 'unspliced']"},{'id': '23', 'type': 'string', 'children': [], 'value': "'spliced'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'unspliced'"},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'enforce'},{'id': '27', 'type': 'False', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '30', 'type': 'False', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '43', '81', '88', '92', '227', '243', '266']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '35', 'type': 'conditional_expression', 'children': ['36', '41', '42'], 'value': 'if'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '46', 'type': 'conditional_expression', 'children': ['47', '54', '57'], 'value': 'if'},{'id': '47', 'type': 'call', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '56', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '57', 'type': 'conditional_expression', 'children': ['58', '60', '65', '66'], 'value': 'if'},{'id': '58', 'type': 'list', 'children': ['59'], 'value': '[layers]'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '65', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '66', 'type': 'list_comprehension', 'children': ['67', '68', '71']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '71', 'type': 'if_clause', 'children': ['72']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'in'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '74', 'type': 'call', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '87'], 'value': '+'},{'id': '85', 'type': 'list', 'children': ['86'], 'value': "['X']"},{'id': '86', 'type': 'string', 'children': [], 'value': "'X'"},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'modified_layers'},{'id': '91', 'type': 'list', 'children': [], 'value': '[]'},{'id': '92', 'type': 'for_statement', 'children': ['93', '94', '95']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '95', 'type': 'block', 'children': ['96', '111']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '99', 'type': 'conditional_expression', 'children': ['100', '103', '106'], 'value': 'if'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '105', 'type': 'string', 'children': [], 'value': "'X'"},{'id': '106', 'type': 'subscript', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '111', 'type': 'if_statement', 'children': ['112', '118']},{'id': '112', 'type': 'boolean_operator', 'children': ['113', '117'], 'value': 'or'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'not_yet_normalized'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'enforce'},{'id': '118', 'type': 'block', 'children': ['119', '140', '160', '174', '183', '189', '220']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '122', 'type': 'conditional_expression', 'children': ['123', '124', '127', '128'], 'value': 'if'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'counts_per_cell'},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'is'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'counts_per_cell'},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '128', 'type': 'conditional_expression', 'children': ['129', '134', '135'], 'value': 'if'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'get_initial_size'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'use_initial_size'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'get_size'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '140', 'type': 'if_statement', 'children': ['141', '150']},{'id': '141', 'type': 'boolean_operator', 'children': ['142', '145'], 'value': 'and'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'is'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'max_proportion_per_cell'},{'id': '144', 'type': 'None', 'children': []},{'id': '145', 'type': '()', 'children': ['146']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148', '149'], 'value': '<'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'max_proportion_per_cell'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'counts_per_cell_quantile'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158', '159']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'max_proportion_per_cell'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'counts_after'},{'id': '163', 'type': 'conditional_expression', 'children': ['164', '170', '173'], 'value': 'if'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'median'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'is'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'counts_per_cell_after'},{'id': '172', 'type': 'None', 'children': []},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'counts_per_cell_after'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'augmented_assignment', 'children': ['176', '177'], 'value': '/='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '+'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'counts_after'},{'id': '179', 'type': '()', 'children': ['180']},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '=='},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'counts_after'},{'id': '182', 'type': 'integer', 'children': [], 'value': '0'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'augmented_assignment', 'children': ['185', '186'], 'value': '+='},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': '=='},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '188', 'type': 'integer', 'children': [], 'value': '0'},{'id': '189', 'type': 'if_statement', 'children': ['190', '194', '205']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'issparse'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'sparsefuncs'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'inplace_row_scale'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '202', 'type': 'binary_operator', 'children': ['203', '204'], 'value': '/'},{'id': '203', 'type': 'integer', 'children': [], 'value': '1'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '205', 'type': 'else_clause', 'children': ['206']},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'augmented_assignment', 'children': ['209', '210'], 'value': '/='},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'subscript', 'children': ['216', '217', '219']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '217', 'type': 'slice', 'children': ['218']},{'id': '218', 'type': 'colon', 'children': []},{'id': '219', 'type': 'None', 'children': []},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'modified_layers'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '239']},{'id': '229', 'type': 'subscript', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '233', 'type': 'conditional_expression', 'children': ['234', '235', '238'], 'value': 'if'},{'id': '234', 'type': 'string', 'children': [], 'value': "'n_counts'"},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '237'], 'value': 'is'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'key_n_counts'},{'id': '237', 'type': 'None', 'children': []},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'key_n_counts'},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'get_size'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '243', 'type': 'if_statement', 'children': ['244', '250']},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '249'], 'value': '>'},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'modified_layers'},{'id': '249', 'type': 'integer', 'children': [], 'value': '0'},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'logg'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '256', 'type': 'argument_list', 'children': ['257', '258']},{'id': '257', 'type': 'string', 'children': [], 'value': "'Normalized count data:'"},{'id': '258', 'type': 'binary_operator', 'children': ['259', '265'], 'value': '+'},{'id': '259', 'type': 'call', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'string', 'children': [], 'value': "', '"},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'modified_layers'},{'id': '265', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '266', 'type': 'return_statement', 'children': ['267']},{'id': '267', 'type': 'conditional_expression', 'children': ['268', '269', '270'], 'value': 'if'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '270', 'type': 'None', 'children': []}
def normalize_per_cell(data, counts_per_cell_after=None, counts_per_cell=None, key_n_counts=None, max_proportion_per_cell=None, use_initial_size=True, layers=['spliced', 'unspliced'], enforce=False, copy=False): adata = data.copy() if copy else data layers = adata.layers.keys() if layers is 'all' else [layers] if isinstance(layers, str) \ else [layer for layer in layers if layer in adata.layers.keys()] layers = ['X'] + layers modified_layers = [] for layer in layers: X = adata.X if layer is 'X' else adata.layers[layer] if not_yet_normalized(X) or enforce: counts = counts_per_cell if counts_per_cell is not None \ else get_initial_size(adata, layer) if use_initial_size else get_size(adata, layer) if max_proportion_per_cell is not None and (0 < max_proportion_per_cell < 1): counts = counts_per_cell_quantile(X, max_proportion_per_cell, counts) counts_after = np.median(counts) if counts_per_cell_after is None else counts_per_cell_after counts /= counts_after + (counts_after == 0) counts += counts == 0 if issparse(X): sparsefuncs.inplace_row_scale(X, 1 / counts) else: X /= np.array(counts[:, None]) modified_layers.append(layer) adata.obs['n_counts' if key_n_counts is None else key_n_counts] = get_size(adata) if len(modified_layers) > 0: logg.info('Normalized count data:', ', '.join(modified_layers) + '.') return adata if copy else None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '35']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_and_normalize'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'min_counts'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'min_counts_u'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'min_cells'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'min_cells_u'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'min_shared_counts'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'min_shared_cells'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'n_top_genes'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '28', 'type': 'string', 'children': [], 'value': "'seurat'"},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '31', 'type': 'True', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '34', 'type': 'False', 'children': []},{'id': '35', 'type': 'block', 'children': ['36', '47', '73', '96', '101', '117', '149', '159', '177']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '39', 'type': 'conditional_expression', 'children': ['40', '45', '46'], 'value': 'if'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '47', 'type': 'if_statement', 'children': ['48', '67']},{'id': '48', 'type': 'boolean_operator', 'children': ['49', '58'], 'value': 'or'},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'not'},{'id': '50', 'type': 'string', 'children': [], 'value': "'spliced'"},{'id': '51', 'type': 'call', 'children': ['52', '57']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'not'},{'id': '59', 'type': 'string', 'children': [], 'value': "'unspliced'"},{'id': '60', 'type': 'call', 'children': ['61', '66']},{'id': '61', 'type': 'attribute', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '66', 'type': 'argument_list', 'children': []},{'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': 'ValueError'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'string', 'children': [], 'value': "'Could not find spliced / unspliced counts.'"},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'filter_genes'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '81', '84', '87', '90', '93']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'min_counts'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'min_counts'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'min_counts_u'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'min_counts_u'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'min_cells'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'min_cells'},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'min_cells_u'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'min_cells_u'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'min_shared_counts'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'min_shared_counts'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'min_shared_cells'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'min_shared_cells'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'normalize_per_cell'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '101', 'type': 'if_statement', 'children': ['102', '105']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'is'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'n_top_genes'},{'id': '104', 'type': 'None', 'children': []},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'filter_genes_dispersion'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111', '114']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'n_top_genes'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'n_top_genes'},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'flavor'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'log_advised'},{'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': 'allclose'},{'id': '124', 'type': 'argument_list', 'children': ['125', '136']},{'id': '125', 'type': 'call', 'children': ['126', '135']},{'id': '126', 'type': 'attribute', 'children': ['127', '134']},{'id': '127', 'type': 'subscript', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '131', 'type': 'slice', 'children': ['132', '133']},{'id': '132', 'type': 'colon', 'children': []},{'id': '133', 'type': 'integer', 'children': [], 'value': '10'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'call', 'children': ['137', '148']},{'id': '137', 'type': 'attribute', 'children': ['138', '147']},{'id': '138', 'type': 'subscript', 'children': ['139', '144']},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '143', 'type': 'string', 'children': [], 'value': "'spliced'"},{'id': '144', 'type': 'slice', 'children': ['145', '146']},{'id': '145', 'type': 'colon', 'children': []},{'id': '146', 'type': 'integer', 'children': [], 'value': '10'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'if_statement', 'children': ['150', '153']},{'id': '150', 'type': 'boolean_operator', 'children': ['151', '152'], 'value': 'and'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'log_advised'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'log1p'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'logg'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'conditional_expression', 'children': ['166', '167', '170'], 'value': 'if'},{'id': '166', 'type': 'string', 'children': [], 'value': "'Logarithmized X.'"},{'id': '167', 'type': 'boolean_operator', 'children': ['168', '169'], 'value': 'and'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'log_advised'},{'id': '170', 'type': 'conditional_expression', 'children': ['171', '172', '173'], 'value': 'if'},{'id': '171', 'type': 'string', 'children': [], 'value': "'Did not modify X as it looks preprocessed already.'"},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '173', 'type': 'conditional_expression', 'children': ['174', '175', '176'], 'value': 'if'},{'id': '174', 'type': 'string', 'children': [], 'value': "'Consider logarithmizing X with `scv.pp.log1p` for better results.'"},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'log_advised'},{'id': '176', 'type': 'string', 'children': [], 'value': "''"},{'id': '177', 'type': 'return_statement', 'children': ['178']},{'id': '178', 'type': 'conditional_expression', 'children': ['179', '180', '181'], 'value': 'if'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '181', 'type': 'None', 'children': []}
def filter_and_normalize(data, min_counts=None, min_counts_u=None, min_cells=None, min_cells_u=None, min_shared_counts=None, min_shared_cells=None, n_top_genes=None, flavor='seurat', log=True, copy=False): adata = data.copy() if copy else data if 'spliced' not in adata.layers.keys() or 'unspliced' not in adata.layers.keys(): raise ValueError('Could not find spliced / unspliced counts.') filter_genes(adata, min_counts=min_counts, min_counts_u=min_counts_u, min_cells=min_cells, min_cells_u=min_cells_u, min_shared_counts=min_shared_counts, min_shared_cells=min_shared_cells,) normalize_per_cell(adata) if n_top_genes is not None: filter_genes_dispersion(adata, n_top_genes=n_top_genes, flavor=flavor) log_advised = np.allclose(adata.X[:10].sum(), adata.layers['spliced'][:10].sum()) if log and log_advised: log1p(adata) logg.info('Logarithmized X.' if log and log_advised else 'Did not modify X as it looks preprocessed already.' if log else 'Consider logarithmizing X with `scv.pp.log1p` for better results.' if log_advised else '') return adata if copy else None
{'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', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ldata'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '62', '75', '88', '119', '199', '229', '254', '276', '298', '320', '342', '439']},{'id': '10', 'type': 'if_statement', 'children': ['11', '30', '36']},{'id': '11', 'type': 'boolean_operator', 'children': ['12', '21'], 'value': 'and'},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'in'},{'id': '13', 'type': 'string', 'children': [], 'value': "'spliced'"},{'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': 'ldata'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'not'},{'id': '22', 'type': 'string', 'children': [], 'value': "'initial_size_spliced'"},{'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': 'ldata'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'set_initial_size'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ldata'},{'id': '36', 'type': 'elif_clause', 'children': ['37', '56']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '47'], 'value': 'and'},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'in'},{'id': '39', 'type': 'string', 'children': [], 'value': "'spliced'"},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'not'},{'id': '48', 'type': 'string', 'children': [], 'value': "'initial_size_spliced'"},{'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': 'adata'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'set_initial_size'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'common_obs'},{'id': '65', 'type': 'call', 'children': ['66', '71']},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'obs_names'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ldata'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'obs_names'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'common_vars'},{'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': 'adata'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'var_names'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ldata'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'var_names'},{'id': '88', 'type': 'if_statement', 'children': ['89', '95']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '94'], 'value': '=='},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'common_obs'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'block', 'children': ['96', '101', '106']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'clean_obs_names'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'clean_obs_names'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ldata'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'common_obs'},{'id': '109', 'type': 'call', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'obs_names'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ldata'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'obs_names'},{'id': '119', 'type': 'if_statement', 'children': ['120', '121', '180']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '121', 'type': 'block', 'children': ['122', '151']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '125', 'type': 'conditional_expression', 'children': ['126', '133', '144'], 'value': 'if'},{'id': '126', 'type': 'call', 'children': ['127', '132']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'common_obs'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '132', 'type': 'argument_list', 'children': []},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '139'], 'value': '>='},{'id': '134', 'type': 'subscript', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'ldata'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'call', 'children': ['145', '150']},{'id': '145', 'type': 'attribute', 'children': ['146', '149']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'ldata'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'common_obs'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '150', 'type': 'argument_list', 'children': []},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '154', 'type': 'conditional_expression', 'children': ['155', '162', '173'], 'value': 'if'},{'id': '155', 'type': 'call', 'children': ['156', '161']},{'id': '156', 'type': 'attribute', 'children': ['157', '160']},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'ldata'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'common_obs'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '168'], 'value': '>='},{'id': '163', 'type': 'subscript', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '167', 'type': 'integer', 'children': [], 'value': '1'},{'id': '168', 'type': 'subscript', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'ldata'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '172', 'type': 'integer', 'children': [], 'value': '1'},{'id': '173', 'type': 'call', 'children': ['174', '179']},{'id': '174', 'type': 'attribute', 'children': ['175', '178']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'common_obs'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '179', 'type': 'argument_list', 'children': []},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182', '189']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '186', 'type': 'identifier', 'children': [], 'value': '_inplace_subset_obs'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'common_obs'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '194']},{'id': '191', 'type': 'pattern_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '193', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '194', 'type': 'expression_list', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'ldata'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'common_obs'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'same_vars'},{'id': '202', 'type': '()', 'children': ['203']},{'id': '203', 'type': 'boolean_operator', 'children': ['204', '217'], 'value': 'and'},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '211'], 'value': '=='},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'var_names'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'var_names'},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '226'], 'value': '=='},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'var_names'},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'var_names'},{'id': '229', 'type': 'if_statement', 'children': ['230', '239']},{'id': '230', 'type': 'boolean_operator', 'children': ['231', '237'], 'value': 'and'},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '236'], 'value': '>'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'common_vars'},{'id': '236', 'type': 'integer', 'children': [], 'value': '0'},{'id': '237', 'type': 'not_operator', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'same_vars'},{'id': '239', 'type': 'block', 'children': ['240', '247']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '244', 'type': 'identifier', 'children': [], 'value': '_inplace_subset_var'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'common_vars'},{'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': '_ldata'},{'id': '251', 'type': 'identifier', 'children': [], 'value': '_inplace_subset_var'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'common_vars'},{'id': '254', 'type': 'for_statement', 'children': ['255', '256', '263']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '256', 'type': 'call', 'children': ['257', '262']},{'id': '257', 'type': 'attribute', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '262', 'type': 'argument_list', 'children': []},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '271']},{'id': '266', 'type': 'subscript', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '271', 'type': 'subscript', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '276', 'type': 'for_statement', 'children': ['277', '278', '285']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '278', 'type': 'call', 'children': ['279', '284']},{'id': '279', 'type': 'attribute', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'obsm'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '284', 'type': 'argument_list', 'children': []},{'id': '285', 'type': 'block', 'children': ['286']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '293']},{'id': '288', 'type': 'subscript', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'obsm'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '293', 'type': 'subscript', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'obsm'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '298', 'type': 'for_statement', 'children': ['299', '300', '307']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '300', 'type': 'call', 'children': ['301', '306']},{'id': '301', 'type': 'attribute', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '306', 'type': 'argument_list', 'children': []},{'id': '307', 'type': 'block', 'children': ['308']},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'assignment', 'children': ['310', '315']},{'id': '310', 'type': 'subscript', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '315', 'type': 'subscript', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '320', 'type': 'for_statement', 'children': ['321', '322', '329']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '322', 'type': 'call', 'children': ['323', '328']},{'id': '323', 'type': 'attribute', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '328', 'type': 'argument_list', 'children': []},{'id': '329', 'type': 'block', 'children': ['330']},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '337']},{'id': '332', 'type': 'subscript', 'children': ['333', '336']},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '337', 'type': 'subscript', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '342', 'type': 'if_statement', 'children': ['343', '354']},{'id': '343', 'type': 'comparison_operator', 'children': ['344', '349'], 'value': '=='},{'id': '344', 'type': 'subscript', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '348', 'type': 'integer', 'children': [], 'value': '1'},{'id': '349', 'type': 'subscript', 'children': ['350', '353']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '353', 'type': 'integer', 'children': [], 'value': '1'},{'id': '354', 'type': 'block', 'children': ['355', '385']},{'id': '355', 'type': 'expression_statement', 'children': ['356']},{'id': '356', 'type': 'assignment', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'same_vars'},{'id': '358', 'type': '()', 'children': ['359']},{'id': '359', 'type': 'boolean_operator', 'children': ['360', '373'], 'value': 'and'},{'id': '360', 'type': 'comparison_operator', 'children': ['361', '367'], 'value': '=='},{'id': '361', 'type': 'call', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '363', 'type': 'argument_list', 'children': ['364']},{'id': '364', 'type': 'attribute', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'var_names'},{'id': '367', 'type': 'call', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'attribute', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'var_names'},{'id': '373', 'type': 'call', 'children': ['374', '377']},{'id': '374', 'type': 'attribute', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '377', 'type': 'argument_list', 'children': ['378']},{'id': '378', 'type': 'comparison_operator', 'children': ['379', '382'], 'value': '=='},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'var_names'},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'var_names'},{'id': '385', 'type': 'if_statement', 'children': ['386', '387', '432']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'same_vars'},{'id': '387', 'type': 'block', 'children': ['388', '410']},{'id': '388', 'type': 'for_statement', 'children': ['389', '390', '397']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '390', 'type': 'call', 'children': ['391', '396']},{'id': '391', 'type': 'attribute', 'children': ['392', '395']},{'id': '392', 'type': 'attribute', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '396', 'type': 'argument_list', 'children': []},{'id': '397', 'type': 'block', 'children': ['398']},{'id': '398', 'type': 'expression_statement', 'children': ['399']},{'id': '399', 'type': 'assignment', 'children': ['400', '405']},{'id': '400', 'type': 'subscript', 'children': ['401', '404']},{'id': '401', 'type': 'attribute', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '405', 'type': 'subscript', 'children': ['406', '409']},{'id': '406', 'type': 'attribute', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '410', 'type': 'for_statement', 'children': ['411', '412', '419']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '412', 'type': 'call', 'children': ['413', '418']},{'id': '413', 'type': 'attribute', 'children': ['414', '417']},{'id': '414', 'type': 'attribute', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'varm'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '418', 'type': 'argument_list', 'children': []},{'id': '419', 'type': 'block', 'children': ['420']},{'id': '420', 'type': 'expression_statement', 'children': ['421']},{'id': '421', 'type': 'assignment', 'children': ['422', '427']},{'id': '422', 'type': 'subscript', 'children': ['423', '426']},{'id': '423', 'type': 'attribute', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'varm'},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '427', 'type': 'subscript', 'children': ['428', '431']},{'id': '428', 'type': 'attribute', 'children': ['429', '430']},{'id': '429', 'type': 'identifier', 'children': [], 'value': '_ldata'},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'varm'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '432', 'type': 'else_clause', 'children': ['433']},{'id': '433', 'type': 'block', 'children': ['434']},{'id': '434', 'type': 'raise_statement', 'children': ['435']},{'id': '435', 'type': 'call', 'children': ['436', '437']},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '437', 'type': 'argument_list', 'children': ['438']},{'id': '438', 'type': 'string', 'children': [], 'value': "'Variable names are not identical.'"},{'id': '439', 'type': 'return_statement', 'children': ['440']},{'id': '440', 'type': 'conditional_expression', 'children': ['441', '442', '443'], 'value': 'if'},{'id': '441', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '443', 'type': 'None', 'children': []}
def merge(adata, ldata, copy=True): if 'spliced' in ldata.layers.keys() and 'initial_size_spliced' not in ldata.obs.keys(): set_initial_size(ldata) elif 'spliced' in adata.layers.keys() and 'initial_size_spliced' not in adata.obs.keys(): set_initial_size(adata) common_obs = adata.obs_names.intersection(ldata.obs_names) common_vars = adata.var_names.intersection(ldata.var_names) if len(common_obs) == 0: clean_obs_names(adata) clean_obs_names(ldata) common_obs = adata.obs_names.intersection(ldata.obs_names) if copy: _adata = adata[common_obs].copy() if adata.shape[1] >= ldata.shape[1] else ldata[common_obs].copy() _ldata = ldata[common_obs].copy() if adata.shape[1] >= ldata.shape[1] else adata[common_obs].copy() else: adata._inplace_subset_obs(common_obs) _adata, _ldata = adata, ldata[common_obs] same_vars = (len(_adata.var_names) == len(_ldata.var_names) and np.all(_adata.var_names == _ldata.var_names)) if len(common_vars) > 0 and not same_vars: _adata._inplace_subset_var(common_vars) _ldata._inplace_subset_var(common_vars) for attr in _ldata.obs.keys(): _adata.obs[attr] = _ldata.obs[attr] for attr in _ldata.obsm.keys(): _adata.obsm[attr] = _ldata.obsm[attr] for attr in _ldata.uns.keys(): _adata.uns[attr] = _ldata.uns[attr] for attr in _ldata.layers.keys(): _adata.layers[attr] = _ldata.layers[attr] if _adata.shape[1] == _ldata.shape[1]: same_vars = (len(_adata.var_names) == len(_ldata.var_names) and np.all(_adata.var_names == _ldata.var_names)) if same_vars: for attr in _ldata.var.keys(): _adata.var[attr] = _ldata.var[attr] for attr in _ldata.varm.keys(): _adata.varm[attr] = _ldata.varm[attr] else: raise ValueError('Variable names are not identical.') return _adata if copy else None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cell_fate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '7', 'type': 'string', 'children': [], 'value': "'clusters'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'disconnected_groups'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self_transitions'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '32', '42', '51', '59', '75', '81', '91', '101', '111', '122', '135', '147', '167', '197', '205', '225', '230', '250', '260']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '24', 'type': 'conditional_expression', 'children': ['25', '30', '31'], 'value': 'if'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'data'},{'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': 'logg'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'computing cell fates'"},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '41', 'type': 'True', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '45', 'type': 'conditional_expression', 'children': ['46', '47', '50'], 'value': 'if'},{'id': '46', 'type': 'integer', 'children': [], 'value': '10'},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '49', 'type': 'None', 'children': []},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'copy'},{'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': 'vgraph'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'VelocityGraph'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66', '69', '72']},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'approx'},{'id': '71', 'type': 'True', 'children': []},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'n_recurse_neighbors'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'vgraph'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'compute_cosines'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '88']},{'id': '83', 'type': 'subscript', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '87', 'type': 'string', 'children': [], 'value': "'velocity_graph'"},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'vgraph'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '98']},{'id': '93', 'type': 'subscript', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '97', 'type': 'string', 'children': [], 'value': "'velocity_graph_neg'"},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'vgraph'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'graph_neg'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'transition_matrix'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self_transitions'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self_transitions'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'eye'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'n_obs'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'fate'},{'id': '125', 'type': 'call', 'children': ['126', '131']},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'inv'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '-'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'I'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '135', 'type': 'if_statement', 'children': ['136', '140']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'issparse'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'fate'},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'fate'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cell_fates'},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'subscript', 'children': ['156', '161']},{'id': '156', 'type': 'subscript', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'fate'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'argmax'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'if_statement', 'children': ['168', '171']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': 'is'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'disconnected_groups'},{'id': '170', 'type': 'None', 'children': []},{'id': '171', 'type': 'block', 'children': ['172', '185']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '175', 'type': 'call', 'children': ['176', '183']},{'id': '176', 'type': 'attribute', 'children': ['177', '182']},{'id': '177', 'type': 'subscript', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'isin'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'disconnected_groups'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'cell_fates'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '190', 'type': 'subscript', 'children': ['191', '196']},{'id': '191', 'type': 'subscript', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': '_adata'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '204']},{'id': '199', 'type': 'subscript', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '203', 'type': 'string', 'children': [], 'value': "'cell_fate'"},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'cell_fates'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '212']},{'id': '207', 'type': 'subscript', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'obs'},{'id': '211', 'type': 'string', 'children': [], 'value': "'cell_fate_confidence'"},{'id': '212', 'type': 'binary_operator', 'children': ['213', '219'], 'value': '/'},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'fate'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'integer', 'children': [], 'value': '1'},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'fate'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'integer', 'children': [], 'value': '1'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'strings_to_categoricals'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'adata'},{'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': 'logg'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237', '240']},{'id': '236', 'type': 'string', 'children': [], 'value': "' finished'"},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '239', 'type': 'True', 'children': []},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '242', 'type': 'conditional_expression', 'children': ['243', '244', '249'], 'value': 'if'},{'id': '243', 'type': 'string', 'children': [], 'value': "' '"},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '248'], 'value': '>'},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '248', 'type': 'integer', 'children': [], 'value': '2'},{'id': '249', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'logg'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'hint'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'concatenated_string', 'children': ['257', '258', '259']},{'id': '257', 'type': 'string', 'children': [], 'value': "'added\\n'"},{'id': '258', 'type': 'string', 'children': [], 'value': "' \\'cell_fate\\', most likely cell fate (adata.obs)\\n'"},{'id': '259', 'type': 'string', 'children': [], 'value': "' \\'cell_fate_confidence\\', confidence of transitioning to the assigned fate (adata.obs)'"},{'id': '260', 'type': 'return_statement', 'children': ['261']},{'id': '261', 'type': 'conditional_expression', 'children': ['262', '263', '264'], 'value': 'if'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '264', 'type': 'None', 'children': []}
def cell_fate(data, groupby='clusters', disconnected_groups=None, self_transitions=False, n_neighbors=None, copy=False): adata = data.copy() if copy else data logg.info('computing cell fates', r=True) n_neighbors = 10 if n_neighbors is None else n_neighbors _adata = adata.copy() vgraph = VelocityGraph(_adata, n_neighbors=n_neighbors, approx=True, n_recurse_neighbors=1) vgraph.compute_cosines() _adata.uns['velocity_graph'] = vgraph.graph _adata.uns['velocity_graph_neg'] = vgraph.graph_neg T = transition_matrix(_adata, self_transitions=self_transitions) I = np.eye(_adata.n_obs) fate = np.linalg.inv(I - T) if issparse(T): fate = fate.A cell_fates = np.array(_adata.obs[groupby][fate.argmax(1)]) if disconnected_groups is not None: idx = _adata.obs[groupby].isin(disconnected_groups) cell_fates[idx] = _adata.obs[groupby][idx] adata.obs['cell_fate'] = cell_fates adata.obs['cell_fate_confidence'] = fate.max(1) / fate.sum(1) strings_to_categoricals(adata) logg.info(' finished', time=True, end=' ' if settings.verbosity > 2 else '\n') logg.hint( 'added\n' ' \'cell_fate\', most likely cell fate (adata.obs)\n' ' \'cell_fate_confidence\', confidence of transitioning to the assigned fate (adata.obs)') return adata if copy else None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'moments'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '7', 'type': 'integer', 'children': [], 'value': '30'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'n_pcs'},{'id': '10', 'type': 'integer', 'children': [], 'value': '30'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '13', 'type': 'string', 'children': [], 'value': "'connectivities'"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '16', 'type': 'string', 'children': [], 'value': "'umap'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'metric'},{'id': '19', 'type': 'string', 'children': [], 'value': "'euclidean'"},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'use_rep'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'recurse_neighbors'},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'renormalize'},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'block', 'children': ['33', '44', '70', '94', '142', '156', '171', '185', '215', '245', '261', '281', '290']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '36', 'type': 'conditional_expression', 'children': ['37', '42', '43'], 'value': 'if'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '44', 'type': 'if_statement', 'children': ['45', '64']},{'id': '45', 'type': 'boolean_operator', 'children': ['46', '55'], 'value': 'or'},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'not'},{'id': '47', 'type': 'string', 'children': [], 'value': "'spliced'"},{'id': '48', 'type': 'call', 'children': ['49', '54']},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'not'},{'id': '56', 'type': 'string', 'children': [], 'value': "'unspliced'"},{'id': '57', 'type': 'call', 'children': ['58', '63']},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'raise_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': "'Could not find spliced / unspliced counts.'"},{'id': '70', 'type': 'if_statement', 'children': ['71', '88']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'list_comprehension', 'children': ['75', '83']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'not_yet_normalized'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'subscript', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '83', 'type': 'for_in_clause', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '85', 'type': 'set', 'children': ['86', '87']},{'id': '86', 'type': 'string', 'children': [], 'value': "'spliced'"},{'id': '87', 'type': 'string', 'children': [], 'value': "'unspliced'"},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'normalize_per_cell'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '94', 'type': 'if_statement', 'children': ['95', '112']},{'id': '95', 'type': 'boolean_operator', 'children': ['96', '105'], 'value': 'or'},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'not'},{'id': '97', 'type': 'string', 'children': [], 'value': "'neighbors'"},{'id': '98', 'type': 'call', 'children': ['99', '104']},{'id': '99', 'type': 'attribute', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '104', 'type': 'argument_list', 'children': []},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'neighbors_to_be_recomputed'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '112', 'type': 'block', 'children': ['113', '122']},{'id': '113', 'type': 'if_statement', 'children': ['114', '117']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'is'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'use_rep'},{'id': '116', 'type': 'None', 'children': []},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'use_rep'},{'id': '121', 'type': 'string', 'children': [], 'value': "'X_pca'"},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127', '130', '133', '136', '139']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'use_rep'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'use_rep'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'n_pcs'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'n_pcs'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'metric'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'metric'},{'id': '142', 'type': 'if_statement', 'children': ['143', '150']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'not'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '145', 'type': 'subscript', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '149', 'type': 'string', 'children': [], 'value': "'neighbors'"},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'raise_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'string', 'children': [], 'value': "'mode can only be \\'connectivities\\' or \\'distances\\''"},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'logg'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '161', 'type': 'argument_list', 'children': ['162', '168']},{'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '+'},{'id': '163', 'type': 'string', 'children': [], 'value': "'computing moments based on '"},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '170', 'type': 'True', 'children': []},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'connectivities'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'get_connectivities'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178', '179', '182']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'recurse_neighbors'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'recurse_neighbors'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '192']},{'id': '187', 'type': 'subscript', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '191', 'type': 'string', 'children': [], 'value': "'Ms'"},{'id': '192', 'type': 'attribute', 'children': ['193', '214']},{'id': '193', 'type': 'call', 'children': ['194', '210']},{'id': '194', 'type': 'attribute', 'children': ['195', '209']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'csr_matrix'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'connectivities'},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'csr_matrix'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'subscript', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '208', 'type': 'string', 'children': [], 'value': "'spliced'"},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '222']},{'id': '217', 'type': 'subscript', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '221', 'type': 'string', 'children': [], 'value': "'Mu'"},{'id': '222', 'type': 'attribute', 'children': ['223', '244']},{'id': '223', 'type': 'call', 'children': ['224', '240']},{'id': '224', 'type': 'attribute', 'children': ['225', '239']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'csr_matrix'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'connectivities'},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'csr_matrix'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'subscript', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '238', 'type': 'string', 'children': [], 'value': "'unspliced'"},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '245', 'type': 'if_statement', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'renormalize'},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'normalize_per_cell'},{'id': '251', 'type': 'argument_list', 'children': ['252', '253', '258']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '255', 'type': 'set', 'children': ['256', '257']},{'id': '256', 'type': 'string', 'children': [], 'value': "'Ms'"},{'id': '257', 'type': 'string', 'children': [], 'value': "'Mu'"},{'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'enforce'},{'id': '260', 'type': 'True', 'children': []},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'logg'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '266', 'type': 'argument_list', 'children': ['267', '268', '271']},{'id': '267', 'type': 'string', 'children': [], 'value': "' finished'"},{'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '270', 'type': 'True', 'children': []},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '273', 'type': 'conditional_expression', 'children': ['274', '275', '280'], 'value': 'if'},{'id': '274', 'type': 'string', 'children': [], 'value': "' '"},{'id': '275', 'type': 'comparison_operator', 'children': ['276', '279'], 'value': '>'},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '279', 'type': 'integer', 'children': [], 'value': '2'},{'id': '280', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'logg'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'hint'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'concatenated_string', 'children': ['288', '289']},{'id': '288', 'type': 'string', 'children': [], 'value': "'added \\n'"},{'id': '289', 'type': 'string', 'children': [], 'value': "' \\'Ms\\' and \\'Mu\\', moments of spliced/unspliced abundances (adata.layers)'"},{'id': '290', 'type': 'return_statement', 'children': ['291']},{'id': '291', 'type': 'conditional_expression', 'children': ['292', '293', '294'], 'value': 'if'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '294', 'type': 'None', 'children': []}
def moments(data, n_neighbors=30, n_pcs=30, mode='connectivities', method='umap', metric='euclidean', use_rep=None, recurse_neighbors=False, renormalize=False, copy=False): adata = data.copy() if copy else data if 'spliced' not in adata.layers.keys() or 'unspliced' not in adata.layers.keys(): raise ValueError('Could not find spliced / unspliced counts.') if any([not_yet_normalized(adata.layers[layer]) for layer in {'spliced', 'unspliced'}]): normalize_per_cell(adata) if 'neighbors' not in adata.uns.keys() or neighbors_to_be_recomputed(adata, n_neighbors=n_neighbors): if use_rep is None: use_rep = 'X_pca' neighbors(adata, n_neighbors=n_neighbors, use_rep=use_rep, n_pcs=n_pcs, method=method, metric=metric) if mode not in adata.uns['neighbors']: raise ValueError('mode can only be \'connectivities\' or \'distances\'') logg.info('computing moments based on ' + str(mode), r=True) connectivities = get_connectivities(adata, mode, n_neighbors=n_neighbors, recurse_neighbors=recurse_neighbors) adata.layers['Ms'] = csr_matrix.dot(connectivities, csr_matrix(adata.layers['spliced'])).astype(np.float32).A adata.layers['Mu'] = csr_matrix.dot(connectivities, csr_matrix(adata.layers['unspliced'])).astype(np.float32).A if renormalize: normalize_per_cell(adata, layers={'Ms', 'Mu'}, enforce=True) logg.info(' finished', time=True, end=' ' if settings.verbosity > 2 else '\n') logg.hint( 'added \n' ' \'Ms\' and \'Mu\', moments of spliced/unspliced abundances (adata.layers)') return adata if copy else None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '41']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'transition_matrix'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'vkey'},{'id': '7', 'type': 'string', 'children': [], 'value': "'velocity'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'backward'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self_transitions'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '19', 'type': 'integer', 'children': [], 'value': '10'},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'perc'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'use_negative_cosines'},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'weight_diffusion'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'scale_diffusion'},{'id': '31', 'type': 'integer', 'children': [], 'value': '1'},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'weight_indirect_neighbors'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'vgraph'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '56', '82', '130', '141', '198', '258', '267', '274', '300', '335', '475']},{'id': '42', 'type': 'if_statement', 'children': ['43', '50']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '47'], 'value': 'not'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '+'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'vkey'},{'id': '46', 'type': 'string', 'children': [], 'value': "'_graph'"},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'uns'},{'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': 'ValueError'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'string', 'children': [], 'value': "'You need to run `tl.velocity_graph` first to compute cosine correlations.'"},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '59', 'type': 'conditional_expression', 'children': ['60', '74', '77'], 'value': 'if'},{'id': '60', 'type': 'call', 'children': ['61', '73']},{'id': '61', 'type': 'attribute', 'children': ['62', '72']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'csr_matrix'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'subscript', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '+'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'vkey'},{'id': '71', 'type': 'string', 'children': [], 'value': "'_graph'"},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'is'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'vgraph'},{'id': '76', 'type': 'None', 'children': []},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'vgraph'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'if_statement', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self_transitions'},{'id': '84', 'type': 'block', 'children': ['85', '100', '110', '123']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'confidence'},{'id': '88', 'type': 'call', 'children': ['89', '99']},{'id': '89', 'type': 'attribute', 'children': ['90', '98']},{'id': '90', 'type': 'attribute', 'children': ['91', '97']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'integer', 'children': [], 'value': '1'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '99', 'type': 'argument_list', 'children': []},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ub'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'percentile'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'confidence'},{'id': '109', 'type': 'integer', 'children': [], 'value': '98'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self_prob'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'clip'},{'id': '117', 'type': 'argument_list', 'children': ['118', '121', '122']},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '-'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ub'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'confidence'},{'id': '121', 'type': 'integer', 'children': [], 'value': '0'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'graph'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'setdiag'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self_prob'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'expm1'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '*'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '141', 'type': 'if_statement', 'children': ['142', '153']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '146'], 'value': 'in'},{'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '+'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'vkey'},{'id': '145', 'type': 'string', 'children': [], 'value': "'_graph_neg'"},{'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': 'adata'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '152', 'type': 'argument_list', 'children': []},{'id': '153', 'type': 'block', 'children': ['154', '164']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'graph_neg'},{'id': '157', 'type': 'subscript', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '+'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'vkey'},{'id': '163', 'type': 'string', 'children': [], 'value': "'_graph_neg'"},{'id': '164', 'type': 'if_statement', 'children': ['165', '166', '179']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'use_negative_cosines'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'augmented_assignment', 'children': ['169', '170'], 'value': '-='},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'expm1'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'binary_operator', 'children': ['176', '178'], 'value': '*'},{'id': '176', 'type': 'unary_operator', 'children': ['177'], 'value': '-'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'graph_neg'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '179', 'type': 'else_clause', 'children': ['180']},{'id': '180', 'type': 'block', 'children': ['181', '192']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'augmented_assignment', 'children': ['183', '184'], 'value': '+='},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'expm1'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '*'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'graph_neg'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'augmented_assignment', 'children': ['194', '197'], 'value': '+='},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '197', 'type': 'integer', 'children': [], 'value': '1'},{'id': '198', 'type': 'if_statement', 'children': ['199', '216']},{'id': '199', 'type': 'boolean_operator', 'children': ['200', '213'], 'value': 'and'},{'id': '200', 'type': 'boolean_operator', 'children': ['201', '210'], 'value': 'and'},{'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'in'},{'id': '202', 'type': 'string', 'children': [], 'value': "'neighbors'"},{'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': 'adata'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': 'is'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'weight_indirect_neighbors'},{'id': '212', 'type': 'None', 'children': []},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': '<'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'weight_indirect_neighbors'},{'id': '215', 'type': 'integer', 'children': [], 'value': '1'},{'id': '216', 'type': 'block', 'children': ['217', '229', '236', '240']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'direct_neighbors'},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '228'], 'value': '>'},{'id': '221', 'type': 'subscript', 'children': ['222', '227']},{'id': '222', 'type': 'subscript', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'uns'},{'id': '226', 'type': 'string', 'children': [], 'value': "'neighbors'"},{'id': '227', 'type': 'string', 'children': [], 'value': "'distances'"},{'id': '228', 'type': 'integer', 'children': [], 'value': '0'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'direct_neighbors'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'setdiag'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'integer', 'children': [], 'value': '1'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'weight_indirect_neighbors'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '243', 'type': 'binary_operator', 'children': ['244', '247'], 'value': '+'},{'id': '244', 'type': 'binary_operator', 'children': ['245', '246'], 'value': '*'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '247', 'type': 'binary_operator', 'children': ['248', '252'], 'value': '*'},{'id': '248', 'type': '()', 'children': ['249']},{'id': '249', 'type': 'binary_operator', 'children': ['250', '251'], 'value': '-'},{'id': '250', 'type': 'integer', 'children': [], 'value': '1'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'direct_neighbors'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'multiply'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '258', 'type': 'if_statement', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'backward'},{'id': '260', 'type': 'block', 'children': ['261']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '274', 'type': 'if_statement', 'children': ['275', '278']},{'id': '275', 'type': 'comparison_operator', 'children': ['276', '277'], 'value': 'is'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '277', 'type': 'None', 'children': []},{'id': '278', 'type': 'block', 'children': ['279']},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'assignment', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'multiply'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'get_connectivities'},{'id': '289', 'type': 'argument_list', 'children': ['290', '291', '294', '297']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '291', 'type': 'keyword_argument', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '293', 'type': 'string', 'children': [], 'value': "'distances'"},{'id': '294', 'type': 'keyword_argument', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'n_neighbors'},{'id': '297', 'type': 'keyword_argument', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'recurse_neighbors'},{'id': '299', 'type': 'True', 'children': []},{'id': '300', 'type': 'if_statement', 'children': ['301', '304']},{'id': '301', 'type': 'comparison_operator', 'children': ['302', '303'], 'value': 'is'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'perc'},{'id': '303', 'type': 'None', 'children': []},{'id': '304', 'type': 'block', 'children': ['305', '317', '329']},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'assignment', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'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': 'percentile'},{'id': '312', 'type': 'argument_list', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'perc'},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'assignment', 'children': ['319', '328']},{'id': '319', 'type': 'subscript', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '323', 'type': 'comparison_operator', 'children': ['324', '327'], 'value': '<'},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '328', 'type': 'integer', 'children': [], 'value': '0'},{'id': '329', 'type': 'expression_statement', 'children': ['330']},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'eliminate_zeros'},{'id': '334', 'type': 'argument_list', 'children': []},{'id': '335', 'type': 'if_statement', 'children': ['336', '350']},{'id': '336', 'type': 'comparison_operator', 'children': ['337', '343'], 'value': 'in'},{'id': '337', 'type': 'binary_operator', 'children': ['338', '339'], 'value': '+'},{'id': '338', 'type': 'string', 'children': [], 'value': "'X_'"},{'id': '339', 'type': 'call', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '343', 'type': 'call', 'children': ['344', '349']},{'id': '344', 'type': 'attribute', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'obsm'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '349', 'type': 'argument_list', 'children': []},{'id': '350', 'type': 'block', 'children': ['351', '375', '385', '393', '415', '424', '468']},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'assignment', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'dists_emb'},{'id': '354', 'type': 'call', 'children': ['355', '361']},{'id': '355', 'type': 'attribute', 'children': ['356', '360']},{'id': '356', 'type': '()', 'children': ['357']},{'id': '357', 'type': 'comparison_operator', 'children': ['358', '359'], 'value': '>'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '359', 'type': 'integer', 'children': [], 'value': '0'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'multiply'},{'id': '361', 'type': 'argument_list', 'children': ['362']},{'id': '362', 'type': 'call', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'squareform'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'pdist'},{'id': '367', 'type': 'argument_list', 'children': ['368']},{'id': '368', 'type': 'subscript', 'children': ['369', '372']},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'adata'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'obsm'},{'id': '372', 'type': 'binary_operator', 'children': ['373', '374'], 'value': '+'},{'id': '373', 'type': 'string', 'children': [], 'value': "'X_'"},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'basis'},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'augmented_assignment', 'children': ['377', '378'], 'value': '*='},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'scale_diffusion'},{'id': '378', 'type': 'call', 'children': ['379', '384']},{'id': '379', 'type': 'attribute', 'children': ['380', '383']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'dists_emb'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '384', 'type': 'argument_list', 'children': []},{'id': '385', 'type': 'expression_statement', 'children': ['386']},{'id': '386', 'type': 'assignment', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'diffusion_kernel'},{'id': '388', 'type': 'call', 'children': ['389', '392']},{'id': '389', 'type': 'attribute', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'dists_emb'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '392', 'type': 'argument_list', 'children': []},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'assignment', 'children': ['395', '398']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'diffusion_kernel'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '398', 'type': 'call', 'children': ['399', '402']},{'id': '399', 'type': 'attribute', 'children': ['400', '401']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '402', 'type': 'argument_list', 'children': ['403']},{'id': '403', 'type': 'binary_operator', 'children': ['404', '412'], 'value': '/'},{'id': '404', 'type': 'binary_operator', 'children': ['405', '407'], 'value': '*'},{'id': '405', 'type': 'unary_operator', 'children': ['406'], 'value': '-'},{'id': '406', 'type': 'float', 'children': [], 'value': '.5'},{'id': '407', 'type': 'binary_operator', 'children': ['408', '411'], 'value': '**'},{'id': '408', 'type': 'attribute', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'dists_emb'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '411', 'type': 'integer', 'children': [], 'value': '2'},{'id': '412', 'type': 'binary_operator', 'children': ['413', '414'], 'value': '**'},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'scale_diffusion'},{'id': '414', 'type': 'integer', 'children': [], 'value': '2'},{'id': '415', 'type': 'expression_statement', 'children': ['416']},{'id': '416', 'type': 'assignment', 'children': ['417', '418']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '418', 'type': 'call', 'children': ['419', '422']},{'id': '419', 'type': 'attribute', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'multiply'},{'id': '422', 'type': 'argument_list', 'children': ['423']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'diffusion_kernel'},{'id': '424', 'type': 'if_statement', 'children': ['425', '429']},{'id': '425', 'type': 'comparison_operator', 'children': ['426', '427', '428'], 'value': '<'},{'id': '426', 'type': 'integer', 'children': [], 'value': '0'},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'weight_diffusion'},{'id': '428', 'type': 'integer', 'children': [], 'value': '1'},{'id': '429', 'type': 'block', 'children': ['430', '455']},{'id': '430', 'type': 'expression_statement', 'children': ['431']},{'id': '431', 'type': 'assignment', 'children': ['432', '435']},{'id': '432', 'type': 'attribute', 'children': ['433', '434']},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'diffusion_kernel'},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '435', 'type': 'call', 'children': ['436', '439']},{'id': '436', 'type': 'attribute', 'children': ['437', '438']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '439', 'type': 'argument_list', 'children': ['440']},{'id': '440', 'type': 'binary_operator', 'children': ['441', '449'], 'value': '/'},{'id': '441', 'type': 'binary_operator', 'children': ['442', '444'], 'value': '*'},{'id': '442', 'type': 'unary_operator', 'children': ['443'], 'value': '-'},{'id': '443', 'type': 'float', 'children': [], 'value': '.5'},{'id': '444', 'type': 'binary_operator', 'children': ['445', '448'], 'value': '**'},{'id': '445', 'type': 'attribute', 'children': ['446', '447']},{'id': '446', 'type': 'identifier', 'children': [], 'value': 'dists_emb'},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '448', 'type': 'integer', 'children': [], 'value': '2'},{'id': '449', 'type': 'binary_operator', 'children': ['450', '454'], 'value': '**'},{'id': '450', 'type': '()', 'children': ['451']},{'id': '451', 'type': 'binary_operator', 'children': ['452', '453'], 'value': '/'},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'scale_diffusion'},{'id': '453', 'type': 'integer', 'children': [], 'value': '2'},{'id': '454', 'type': 'integer', 'children': [], 'value': '2'},{'id': '455', 'type': 'expression_statement', 'children': ['456']},{'id': '456', 'type': 'assignment', 'children': ['457', '458']},{'id': '457', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '458', 'type': 'binary_operator', 'children': ['459', '465'], 'value': '+'},{'id': '459', 'type': 'binary_operator', 'children': ['460', '464'], 'value': '*'},{'id': '460', 'type': '()', 'children': ['461']},{'id': '461', 'type': 'binary_operator', 'children': ['462', '463'], 'value': '-'},{'id': '462', 'type': 'integer', 'children': [], 'value': '1'},{'id': '463', 'type': 'identifier', 'children': [], 'value': 'weight_diffusion'},{'id': '464', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '465', 'type': 'binary_operator', 'children': ['466', '467'], 'value': '*'},{'id': '466', 'type': 'identifier', 'children': [], 'value': 'weight_diffusion'},{'id': '467', 'type': 'identifier', 'children': [], 'value': 'diffusion_kernel'},{'id': '468', 'type': 'expression_statement', 'children': ['469']},{'id': '469', 'type': 'assignment', 'children': ['470', '471']},{'id': '470', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '471', 'type': 'call', 'children': ['472', '473']},{'id': '472', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '473', 'type': 'argument_list', 'children': ['474']},{'id': '474', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '475', 'type': 'return_statement', 'children': ['476']},{'id': '476', 'type': 'identifier', 'children': [], 'value': 'T'}
def transition_matrix(adata, vkey='velocity', basis=None, backward=False, self_transitions=True, scale=10, perc=None, use_negative_cosines=False, weight_diffusion=0, scale_diffusion=1, weight_indirect_neighbors=None, n_neighbors=None, vgraph=None): if vkey+'_graph' not in adata.uns: raise ValueError('You need to run `tl.velocity_graph` first to compute cosine correlations.') graph = csr_matrix(adata.uns[vkey + '_graph']).copy() if vgraph is None else vgraph.copy() if self_transitions: confidence = graph.max(1).A.flatten() ub = np.percentile(confidence, 98) self_prob = np.clip(ub - confidence, 0, 1) graph.setdiag(self_prob) T = np.expm1(graph * scale) if vkey + '_graph_neg' in adata.uns.keys(): graph_neg = adata.uns[vkey + '_graph_neg'] if use_negative_cosines: T -= np.expm1(-graph_neg * scale) else: T += np.expm1(graph_neg * scale) T.data += 1 if 'neighbors' in adata.uns.keys() and weight_indirect_neighbors is not None and weight_indirect_neighbors < 1: direct_neighbors = adata.uns['neighbors']['distances'] > 0 direct_neighbors.setdiag(1) w = weight_indirect_neighbors T = w * T + (1-w) * direct_neighbors.multiply(T) if backward: T = T.T T = normalize(T) if n_neighbors is not None: T = T.multiply(get_connectivities(adata, mode='distances', n_neighbors=n_neighbors, recurse_neighbors=True)) if perc is not None: threshold = np.percentile(T.data, perc) T.data[T.data < threshold] = 0 T.eliminate_zeros() if 'X_' + str(basis) in adata.obsm.keys(): dists_emb = (T > 0).multiply(squareform(pdist(adata.obsm['X_' + basis]))) scale_diffusion *= dists_emb.data.mean() diffusion_kernel = dists_emb.copy() diffusion_kernel.data = np.exp(-.5 * dists_emb.data ** 2 / scale_diffusion ** 2) T = T.multiply(diffusion_kernel) if 0 < weight_diffusion < 1: diffusion_kernel.data = np.exp(-.5 * dists_emb.data ** 2 / (scale_diffusion/2) ** 2) T = (1-weight_diffusion) * T + weight_diffusion * diffusion_kernel T = normalize(T) return T
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_holder'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '6', 'type': 'block', 'children': ['7', '15', '176']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '15', 'type': 'if_statement', 'children': ['16', '21', '152']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'in'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '21', 'type': 'block', 'children': ['22', '138']},{'id': '22', 'type': 'if_statement', 'children': ['23', '31', '46', '99']},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'id': '24', 'type': 'subscript', 'children': ['25', '30']},{'id': '25', 'type': 'subscript', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '30', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '41']},{'id': '34', 'type': 'subscript', 'children': ['35', '40']},{'id': '35', 'type': 'subscript', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '40', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '41', 'type': 'subscript', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '45', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '46', 'type': 'elif_clause', 'children': ['47', '62']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'same_sign'},{'id': '49', 'type': 'argument_list', 'children': ['50', '57']},{'id': '50', 'type': 'subscript', 'children': ['51', '56']},{'id': '51', 'type': 'subscript', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '56', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '57', 'type': 'subscript', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '61', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '72']},{'id': '65', 'type': 'subscript', 'children': ['66', '71']},{'id': '66', 'type': 'subscript', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '71', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'average_price'},{'id': '74', 'type': 'argument_list', 'children': ['75', '82', '89', '94']},{'id': '75', 'type': 'subscript', 'children': ['76', '81']},{'id': '76', 'type': 'subscript', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '81', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '82', 'type': 'subscript', 'children': ['83', '88']},{'id': '83', 'type': 'subscript', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '88', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '89', 'type': 'subscript', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '93', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '94', 'type': 'subscript', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '98', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '99', 'type': 'else_clause', 'children': ['100']},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'if_statement', 'children': ['102', '123']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'same_sign'},{'id': '104', 'type': 'argument_list', 'children': ['105', '110']},{'id': '105', 'type': 'subscript', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '109', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '110', 'type': 'binary_operator', 'children': ['111', '118'], 'value': '+'},{'id': '111', 'type': 'subscript', 'children': ['112', '117']},{'id': '112', 'type': 'subscript', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '117', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '118', 'type': 'subscript', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '122', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '133']},{'id': '126', 'type': 'subscript', 'children': ['127', '132']},{'id': '127', 'type': 'subscript', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '132', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '133', 'type': 'subscript', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '137', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'augmented_assignment', 'children': ['140', '147'], 'value': '+='},{'id': '140', 'type': 'subscript', 'children': ['141', '146']},{'id': '141', 'type': 'subscript', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '146', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '147', 'type': 'subscript', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '151', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '152', 'type': 'else_clause', 'children': ['153']},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '161']},{'id': '156', 'type': 'subscript', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '161', 'type': 'dictionary', 'children': ['162', '169']},{'id': '162', 'type': 'pair', 'children': ['163', '164']},{'id': '163', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '164', 'type': 'subscript', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '168', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '169', 'type': 'pair', 'children': ['170', '171']},{'id': '170', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '171', 'type': 'subscript', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '175', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '176', 'type': 'if_statement', 'children': ['177', '185']},{'id': '177', 'type': 'not_operator', 'children': ['178']},{'id': '178', 'type': 'subscript', 'children': ['179', '184']},{'id': '179', 'type': 'subscript', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '184', 'type': 'string', 'children': [], 'value': "'quantity'"},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '195']},{'id': '188', 'type': 'subscript', 'children': ['189', '194']},{'id': '189', 'type': 'subscript', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'holder'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'subject_symbol'},{'id': '194', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '195', 'type': 'integer', 'children': [], 'value': '0'}
def update_holder(self, holder): subject_symbol = self.subject.symbol if subject_symbol in holder.state: if not holder.state[subject_symbol]['quantity']: holder.state[subject_symbol]['value'] = self.details['value'] elif same_sign( holder.state[subject_symbol]['quantity'], self.details['quantity']): holder.state[subject_symbol]['value'] = average_price( holder.state[subject_symbol]['quantity'], holder.state[subject_symbol]['value'], self.details['quantity'], self.details['value'] ) else: if same_sign( self.details['quantity'], holder.state[subject_symbol]['quantity'] + self.details['quantity']): holder.state[subject_symbol]['value'] = self.details['value'] holder.state[subject_symbol]['quantity'] += self.details['quantity'] else: holder.state[subject_symbol] = { 'quantity': self.details['quantity'], 'value': self.details['value'] } if not holder.state[subject_symbol]['quantity']: holder.state[subject_symbol]['value'] = 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'addImagingColumns'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'msname'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ack'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '14', '27', '35', '53', '57', '89', '109', '160', '211', '331', '349', '364', '373', '383', '397', '407']},{'id': '9', 'type': 'import_statement', 'children': ['10']},{'id': '10', 'type': 'aliased_import', 'children': ['11', '13']},{'id': '11', 'type': 'dotted_name', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21', '24']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'msname'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'readonly'},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ack'},{'id': '26', 'type': 'False', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'cnames'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'colnames'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'try_statement', 'children': ['36', '46']},{'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': 'cdesc'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'getcoldesc'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': "'DATA'"},{'id': '46', 'type': 'except_clause', 'children': ['47']},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'raise_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': "'Column DATA does not exist'"},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'hasTiled'},{'id': '56', 'type': 'False', 'children': []},{'id': '57', 'type': 'try_statement', 'children': ['58', '83']},{'id': '58', 'type': 'block', 'children': ['59', '68']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'dminfo'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'getdminfo'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': '"DATA"'},{'id': '68', 'type': 'if_statement', 'children': ['69', '78']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '77'], 'value': '=='},{'id': '70', 'type': 'subscript', 'children': ['71', '74']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dminfo'},{'id': '73', 'type': 'string', 'children': [], 'value': "'TYPE'"},{'id': '74', 'type': 'slice', 'children': ['75', '76']},{'id': '75', 'type': 'colon', 'children': []},{'id': '76', 'type': 'integer', 'children': [], 'value': '5'},{'id': '77', 'type': 'string', 'children': [], 'value': "'Tiled'"},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'hasTiled'},{'id': '82', 'type': 'True', 'children': []},{'id': '83', 'type': 'except_clause', 'children': ['84']},{'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': 'hasTiled'},{'id': '88', 'type': 'False', 'children': []},{'id': '89', 'type': 'if_statement', 'children': ['90', '92']},{'id': '90', 'type': 'not_operator', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'hasTiled'},{'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': 'dminfo'},{'id': '96', 'type': 'dictionary', 'children': ['97', '100']},{'id': '97', 'type': 'pair', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': "'TYPE'"},{'id': '99', 'type': 'string', 'children': [], 'value': "'TiledShapeStMan'"},{'id': '100', 'type': 'pair', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': "'SPEC'"},{'id': '102', 'type': 'dictionary', 'children': ['103']},{'id': '103', 'type': 'pair', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': "'DEFAULTTILESHAPE'"},{'id': '105', 'type': 'list', 'children': ['106', '107', '108'], 'value': '[4, 32, 128]'},{'id': '106', 'type': 'integer', 'children': [], 'value': '4'},{'id': '107', 'type': 'integer', 'children': [], 'value': '32'},{'id': '108', 'type': 'integer', 'children': [], 'value': '128'},{'id': '109', 'type': 'if_statement', 'children': ['110', '113', '121']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'in'},{'id': '111', 'type': 'string', 'children': [], 'value': "'MODEL_DATA'"},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'cnames'},{'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': 'six'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': '"Column MODEL_DATA not added; it already exists"'},{'id': '121', 'type': 'else_clause', 'children': ['122']},{'id': '122', 'type': 'block', 'children': ['123', '129', '135', '150']},{'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': 'dminfo'},{'id': '127', 'type': 'string', 'children': [], 'value': "'NAME'"},{'id': '128', 'type': 'string', 'children': [], 'value': "'modeldata'"},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '134']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'cdesc'},{'id': '133', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '134', 'type': 'string', 'children': [], 'value': "'The model data column'"},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'addcols'},{'id': '140', 'type': 'argument_list', 'children': ['141', '149']},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'maketabdesc'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'makecoldesc'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': "'MODEL_DATA'"},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'cdesc'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'dminfo'},{'id': '150', 'type': 'if_statement', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'ack'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'string', 'children': [], 'value': '"added column MODEL_DATA"'},{'id': '160', 'type': 'if_statement', 'children': ['161', '164', '172']},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': 'in'},{'id': '162', 'type': 'string', 'children': [], 'value': "'CORRECTED_DATA'"},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'cnames'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'string', 'children': [], 'value': '"Column CORRECTED_DATA not added; it already exists"'},{'id': '172', 'type': 'else_clause', 'children': ['173']},{'id': '173', 'type': 'block', 'children': ['174', '180', '186', '201']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '179']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'dminfo'},{'id': '178', 'type': 'string', 'children': [], 'value': "'NAME'"},{'id': '179', 'type': 'string', 'children': [], 'value': "'correcteddata'"},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '185']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'cdesc'},{'id': '184', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '185', 'type': 'string', 'children': [], 'value': "'The corrected data column'"},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'addcols'},{'id': '191', 'type': 'argument_list', 'children': ['192', '200']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'maketabdesc'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'makecoldesc'},{'id': '197', 'type': 'argument_list', 'children': ['198', '199']},{'id': '198', 'type': 'string', 'children': [], 'value': "'CORRECTED_DATA'"},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'cdesc'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'dminfo'},{'id': '201', 'type': 'if_statement', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'ack'},{'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': 'six'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'string', 'children': [], 'value': '"\'added column CORRECTED_DATA"'},{'id': '211', 'type': 'if_statement', 'children': ['212', '215', '223']},{'id': '212', 'type': 'comparison_operator', 'children': ['213', '214'], 'value': 'in'},{'id': '213', 'type': 'string', 'children': [], 'value': "'IMAGING_WEIGHT'"},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'cnames'},{'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': 'six'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'string', 'children': [], 'value': '"Column IMAGING_WEIGHT not added; it already exists"'},{'id': '223', 'type': 'else_clause', 'children': ['224']},{'id': '224', 'type': 'block', 'children': ['225', '229', '240', '272', '289', '304', '310', '321']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'shp'},{'id': '228', 'type': 'list', 'children': [], 'value': '[]'},{'id': '229', 'type': 'if_statement', 'children': ['230', '233']},{'id': '230', 'type': 'comparison_operator', 'children': ['231', '232'], 'value': 'in'},{'id': '231', 'type': 'string', 'children': [], 'value': "'shape'"},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'cdesc'},{'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': 'shp'},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'cdesc'},{'id': '239', 'type': 'string', 'children': [], 'value': "'shape'"},{'id': '240', 'type': 'if_statement', 'children': ['241', '247', '255']},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '246'], 'value': '>'},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'shp'},{'id': '246', 'type': 'integer', 'children': [], 'value': '0'},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'shp'},{'id': '251', 'type': 'list', 'children': ['252'], 'value': '[shp[0]]'},{'id': '252', 'type': 'subscript', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'shp'},{'id': '254', 'type': 'integer', 'children': [], 'value': '0'},{'id': '255', 'type': 'else_clause', 'children': ['256']},{'id': '256', 'type': 'block', 'children': ['257']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'shp'},{'id': '260', 'type': 'list', 'children': ['261'], 'value': "[t.getcell('DATA', 0).shape[0]]"},{'id': '261', 'type': 'subscript', 'children': ['262', '271']},{'id': '262', 'type': 'attribute', 'children': ['263', '270']},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'getcell'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269']},{'id': '268', 'type': 'string', 'children': [], 'value': "'DATA'"},{'id': '269', 'type': 'integer', 'children': [], 'value': '0'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '271', 'type': 'integer', 'children': [], 'value': '0'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'cd'},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'makearrcoldesc'},{'id': '277', 'type': 'argument_list', 'children': ['278', '279', '280', '283', '286']},{'id': '278', 'type': 'string', 'children': [], 'value': "'IMAGING_WEIGHT'"},{'id': '279', 'type': 'integer', 'children': [], 'value': '0'},{'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '282', 'type': 'integer', 'children': [], 'value': '1'},{'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'shp'},{'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'valuetype'},{'id': '288', 'type': 'string', 'children': [], 'value': "'float'"},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'dminfo'},{'id': '292', 'type': 'dictionary', 'children': ['293', '296']},{'id': '293', 'type': 'pair', 'children': ['294', '295']},{'id': '294', 'type': 'string', 'children': [], 'value': "'TYPE'"},{'id': '295', 'type': 'string', 'children': [], 'value': "'TiledShapeStMan'"},{'id': '296', 'type': 'pair', 'children': ['297', '298']},{'id': '297', 'type': 'string', 'children': [], 'value': "'SPEC'"},{'id': '298', 'type': 'dictionary', 'children': ['299']},{'id': '299', 'type': 'pair', 'children': ['300', '301']},{'id': '300', 'type': 'string', 'children': [], 'value': "'DEFAULTTILESHAPE'"},{'id': '301', 'type': 'list', 'children': ['302', '303'], 'value': '[32, 128]'},{'id': '302', 'type': 'integer', 'children': [], 'value': '32'},{'id': '303', 'type': 'integer', 'children': [], 'value': '128'},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'assignment', 'children': ['306', '309']},{'id': '306', 'type': 'subscript', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'dminfo'},{'id': '308', 'type': 'string', 'children': [], 'value': "'NAME'"},{'id': '309', 'type': 'string', 'children': [], 'value': "'imagingweight'"},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'call', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'addcols'},{'id': '315', 'type': 'argument_list', 'children': ['316', '320']},{'id': '316', 'type': 'call', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'maketabdesc'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'cd'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'dminfo'},{'id': '321', 'type': 'if_statement', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'ack'},{'id': '323', 'type': 'block', 'children': ['324']},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'string', 'children': [], 'value': '"added column IMAGING_WEIGHT"'},{'id': '331', 'type': 'if_statement', 'children': ['332', '340']},{'id': '332', 'type': 'comparison_operator', 'children': ['333', '334'], 'value': 'in'},{'id': '333', 'type': 'string', 'children': [], 'value': "'CHANNEL_SELECTION'"},{'id': '334', 'type': 'call', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'colkeywordnames'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'string', 'children': [], 'value': "'MODEL_DATA'"},{'id': '340', 'type': 'block', 'children': ['341']},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'call', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'removecolkeyword'},{'id': '346', 'type': 'argument_list', 'children': ['347', '348']},{'id': '347', 'type': 'string', 'children': [], 'value': "'MODEL_DATA'"},{'id': '348', 'type': 'string', 'children': [], 'value': "'CHANNEL_SELECTION'"},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'assignment', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'tspw'},{'id': '352', 'type': 'call', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '354', 'type': 'argument_list', 'children': ['355', '361']},{'id': '355', 'type': 'call', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'getkeyword'},{'id': '359', 'type': 'argument_list', 'children': ['360']},{'id': '360', 'type': 'string', 'children': [], 'value': "'SPECTRAL_WINDOW'"},{'id': '361', 'type': 'keyword_argument', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'ack'},{'id': '363', 'type': 'False', 'children': []},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'assignment', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'nchans'},{'id': '367', 'type': 'call', 'children': ['368', '371']},{'id': '368', 'type': 'attribute', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'tspw'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'getcol'},{'id': '371', 'type': 'argument_list', 'children': ['372']},{'id': '372', 'type': 'string', 'children': [], 'value': "'NUM_CHAN'"},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'assignment', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'chans'},{'id': '376', 'type': 'list_comprehension', 'children': ['377', '380']},{'id': '377', 'type': 'list', 'children': ['378', '379'], 'value': '[0, nch]'},{'id': '378', 'type': 'integer', 'children': [], 'value': '0'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'nch'},{'id': '380', 'type': 'for_in_clause', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'nch'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'nchans'},{'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': 't'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'putcolkeyword'},{'id': '388', 'type': 'argument_list', 'children': ['389', '390', '391']},{'id': '389', 'type': 'string', 'children': [], 'value': "'MODEL_DATA'"},{'id': '390', 'type': 'string', 'children': [], 'value': "'CHANNEL_SELECTION'"},{'id': '391', 'type': 'call', 'children': ['392', '395']},{'id': '392', 'type': 'attribute', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'int32'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'chans'},{'id': '397', 'type': 'if_statement', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'ack'},{'id': '399', 'type': 'block', 'children': ['400']},{'id': '400', 'type': 'expression_statement', 'children': ['401']},{'id': '401', 'type': 'call', 'children': ['402', '405']},{'id': '402', 'type': 'attribute', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '405', 'type': 'argument_list', 'children': ['406']},{'id': '406', 'type': 'string', 'children': [], 'value': '"defined keyword CHANNEL_SELECTION in column MODEL_DATA"'},{'id': '407', 'type': 'expression_statement', 'children': ['408']},{'id': '408', 'type': 'call', 'children': ['409', '412']},{'id': '409', 'type': 'attribute', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '412', 'type': 'argument_list', 'children': []}
def addImagingColumns(msname, ack=True): import numpy as np t = table(msname, readonly=False, ack=False) cnames = t.colnames() try: cdesc = t.getcoldesc('DATA') except: raise ValueError('Column DATA does not exist') hasTiled = False try: dminfo = t.getdminfo("DATA") if dminfo['TYPE'][:5] == 'Tiled': hasTiled = True except: hasTiled = False if not hasTiled: dminfo = {'TYPE': 'TiledShapeStMan', 'SPEC': {'DEFAULTTILESHAPE': [4, 32, 128]}} if 'MODEL_DATA' in cnames: six.print_("Column MODEL_DATA not added; it already exists") else: dminfo['NAME'] = 'modeldata' cdesc['comment'] = 'The model data column' t.addcols(maketabdesc(makecoldesc('MODEL_DATA', cdesc)), dminfo) if ack: six.print_("added column MODEL_DATA") if 'CORRECTED_DATA' in cnames: six.print_("Column CORRECTED_DATA not added; it already exists") else: dminfo['NAME'] = 'correcteddata' cdesc['comment'] = 'The corrected data column' t.addcols(maketabdesc(makecoldesc('CORRECTED_DATA', cdesc)), dminfo) if ack: six.print_("'added column CORRECTED_DATA") if 'IMAGING_WEIGHT' in cnames: six.print_("Column IMAGING_WEIGHT not added; it already exists") else: shp = [] if 'shape' in cdesc: shp = cdesc['shape'] if len(shp) > 0: shp = [shp[0]] else: shp = [t.getcell('DATA', 0).shape[0]] cd = makearrcoldesc('IMAGING_WEIGHT', 0, ndim=1, shape=shp, valuetype='float') dminfo = {'TYPE': 'TiledShapeStMan', 'SPEC': {'DEFAULTTILESHAPE': [32, 128]}} dminfo['NAME'] = 'imagingweight' t.addcols(maketabdesc(cd), dminfo) if ack: six.print_("added column IMAGING_WEIGHT") if 'CHANNEL_SELECTION' in t.colkeywordnames('MODEL_DATA'): t.removecolkeyword('MODEL_DATA', 'CHANNEL_SELECTION') tspw = table(t.getkeyword('SPECTRAL_WINDOW'), ack=False) nchans = tspw.getcol('NUM_CHAN') chans = [[0, nch] for nch in nchans] t.putcolkeyword('MODEL_DATA', 'CHANNEL_SELECTION', np.int32(chans)) if ack: six.print_("defined keyword CHANNEL_SELECTION in column MODEL_DATA") t.flush()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'msregularize'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'msname'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'newname'},{'id': '6', 'type': 'block', 'children': ['7', '14', '23', '27', '252', '307', '314', '322']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'msname'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': "'unique ANTENNA1,ANTENNA2'"},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'nadded'},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'for_statement', 'children': ['28', '29', '37']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'tsub'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'list', 'children': ['35', '36'], 'value': "['TIME', 'DATA_DESC_ID']"},{'id': '35', 'type': 'string', 'children': [], 'value': "'TIME'"},{'id': '36', 'type': 'string', 'children': [], 'value': "'DATA_DESC_ID'"},{'id': '37', 'type': 'block', 'children': ['38', '52', '62']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'nmissing'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '47'], 'value': '-'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'tsub'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'if_statement', 'children': ['53', '56']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '<'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'nmissing'},{'id': '55', 'type': 'integer', 'children': [], 'value': '0'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'raise_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': '"A time/band chunk has too many rows"'},{'id': '62', 'type': 'if_statement', 'children': ['63', '66']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '>'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'nmissing'},{'id': '65', 'type': 'integer', 'children': [], 'value': '0'},{'id': '66', 'type': 'block', 'children': ['67', '85', '103', '112', '121', '130', '152', '166', '206', '227', '248']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ant1'},{'id': '70', 'type': 'call', 'children': ['71', '82']},{'id': '71', 'type': 'attribute', 'children': ['72', '81']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'getcol'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': "'ANTENNA1'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "' '"},{'id': '84', 'type': 'string', 'children': [], 'value': "','"},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ant2'},{'id': '88', 'type': 'call', 'children': ['89', '100']},{'id': '89', 'type': 'attribute', 'children': ['90', '99']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'str'},{'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': 't1'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'getcol'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'string', 'children': [], 'value': "'ANTENNA2'"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': "' '"},{'id': '102', 'type': 'string', 'children': [], 'value': "','"},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ant1'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'tsub'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'getcol'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'string', 'children': [], 'value': "'ANTENNA1'"},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ant2'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'tsub'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'getcol'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': "'ANTENNA2'"},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'taql'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '+'},{'id': '128', 'type': 'string', 'children': [], 'value': "'select from $t1 where !any(ANTENNA1 == $ant1 &&'"},{'id': '129', 'type': 'string', 'children': [], 'value': "' ANTENNA2 == $ant2)'"},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137', '142', '147']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'nmissing'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'tsub'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'if_statement', 'children': ['153', '160']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '159'], 'value': '!='},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'nmissing'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'raise_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'string', 'children': [], 'value': '"A time/band chunk behaves strangely"'},{'id': '166', 'type': 'if_statement', 'children': ['167', '170', '197']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': '=='},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'nadded'},{'id': '169', 'type': 'integer', 'children': [], 'value': '0'},{'id': '170', 'type': 'block', 'children': ['171', '185']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'tnew'},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '178', 'type': 'argument_list', 'children': ['179', '182']},{'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '+'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'newname'},{'id': '181', 'type': 'string', 'children': [], 'value': '"_add"'},{'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'deep'},{'id': '184', 'type': 'True', 'children': []},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'tnew'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '190', 'type': 'argument_list', 'children': ['191', '194']},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '+'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'newname'},{'id': '193', 'type': 'string', 'children': [], 'value': '"_add"'},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'readonly'},{'id': '196', 'type': 'False', 'children': []},{'id': '197', 'type': 'else_clause', 'children': ['198']},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'copyrows'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'tnew'},{'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': 'tnew'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'putcell'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213', '220']},{'id': '212', 'type': 'string', 'children': [], 'value': "'TIME'"},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'nadded'},{'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '+'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'nadded'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'nmissing'},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'tsub'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'getcell'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226']},{'id': '225', 'type': 'string', 'children': [], 'value': "'TIME'"},{'id': '226', 'type': 'integer', 'children': [], 'value': '0'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'tnew'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'putcell'},{'id': '232', 'type': 'argument_list', 'children': ['233', '234', '241']},{'id': '233', 'type': 'string', 'children': [], 'value': "'DATA_DESC_ID'"},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '236', 'type': 'argument_list', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'nadded'},{'id': '238', 'type': 'binary_operator', 'children': ['239', '240'], 'value': '+'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'nadded'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'nmissing'},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'tsub'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'getcell'},{'id': '245', 'type': 'argument_list', 'children': ['246', '247']},{'id': '246', 'type': 'string', 'children': [], 'value': "'DATA_DESC_ID'"},{'id': '247', 'type': 'integer', 'children': [], 'value': '0'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'augmented_assignment', 'children': ['250', '251'], 'value': '+='},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'nadded'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'nmissing'},{'id': '252', 'type': 'if_statement', 'children': ['253', '256', '294']},{'id': '253', 'type': 'comparison_operator', 'children': ['254', '255'], 'value': '>'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'nadded'},{'id': '255', 'type': 'integer', 'children': [], 'value': '0'},{'id': '256', 'type': 'block', 'children': ['257', '262', '267', '276', '285']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'taql'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'string', 'children': [], 'value': "'update $tnew set DATA=0+0i'"},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'taql'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'string', 'children': [], 'value': "'update $tnew set FLAG=True'"},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'tcomb'},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'list', 'children': ['274', '275'], 'value': '[t, tnew]'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'tnew'},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'tcomb'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'rename'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'binary_operator', 'children': ['283', '284'], 'value': '+'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'newname'},{'id': '284', 'type': 'string', 'children': [], 'value': "'_adds'"},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'tcombs'},{'id': '288', 'type': 'call', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'tcomb'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'string', 'children': [], 'value': "'TIME,DATA_DESC_ID,ANTENNA1,ANTENNA2'"},{'id': '294', 'type': 'else_clause', 'children': ['295']},{'id': '295', 'type': 'block', 'children': ['296']},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'tcombs'},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'keyword_argument', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '306', 'type': 'integer', 'children': [], 'value': '0'},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'tcombs'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'rename'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'newname'},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '319', 'type': 'argument_list', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'newname'},{'id': '321', 'type': 'string', 'children': [], 'value': "'has been created; it references the original MS'"},{'id': '322', 'type': 'if_statement', 'children': ['323', '326', '340']},{'id': '323', 'type': 'comparison_operator', 'children': ['324', '325'], 'value': '>'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'nadded'},{'id': '325', 'type': 'integer', 'children': [], 'value': '0'},{'id': '326', 'type': 'block', 'children': ['327']},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'call', 'children': ['329', '332']},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '332', 'type': 'argument_list', 'children': ['333', '334', '337', '338', '339']},{'id': '333', 'type': 'string', 'children': [], 'value': "' and'"},{'id': '334', 'type': 'binary_operator', 'children': ['335', '336'], 'value': '+'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'newname'},{'id': '336', 'type': 'string', 'children': [], 'value': "'_adds'"},{'id': '337', 'type': 'string', 'children': [], 'value': "'containing'"},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'nadded'},{'id': '339', 'type': 'string', 'children': [], 'value': "'new rows'"},{'id': '340', 'type': 'else_clause', 'children': ['341']},{'id': '341', 'type': 'block', 'children': ['342']},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'call', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '347', 'type': 'argument_list', 'children': ['348']},{'id': '348', 'type': 'string', 'children': [], 'value': "' no rows needed to be added'"}
def msregularize(msname, newname): t = table(msname) t1 = t.sort('unique ANTENNA1,ANTENNA2') nadded = 0 for tsub in t.iter(['TIME', 'DATA_DESC_ID']): nmissing = t1.nrows() - tsub.nrows() if nmissing < 0: raise ValueError("A time/band chunk has too many rows") if nmissing > 0: ant1 = str(t1.getcol('ANTENNA1')).replace(' ', ',') ant2 = str(t1.getcol('ANTENNA2')).replace(' ', ',') ant1 = tsub.getcol('ANTENNA1') ant2 = tsub.getcol('ANTENNA2') t2 = taql('select from $t1 where !any(ANTENNA1 == $ant1 &&' + ' ANTENNA2 == $ant2)') six.print_(nmissing, t1.nrows(), tsub.nrows(), t2.nrows()) if t2.nrows() != nmissing: raise ValueError("A time/band chunk behaves strangely") if nadded == 0: tnew = t2.copy(newname + "_add", deep=True) tnew = table(newname + "_add", readonly=False) else: t2.copyrows(tnew) tnew.putcell('TIME', range(nadded, nadded + nmissing), tsub.getcell('TIME', 0)) tnew.putcell('DATA_DESC_ID', range(nadded, nadded + nmissing), tsub.getcell('DATA_DESC_ID', 0)) nadded += nmissing if nadded > 0: taql('update $tnew set DATA=0+0i') taql('update $tnew set FLAG=True') tcomb = table([t, tnew]) tcomb.rename(newname + '_adds') tcombs = tcomb.sort('TIME,DATA_DESC_ID,ANTENNA1,ANTENNA2') else: tcombs = t.query(offset=0) tcombs.rename(newname) six.print_(newname, 'has been created; it references the original MS') if nadded > 0: six.print_(' and', newname + '_adds', 'containing', nadded, 'new rows') else: six.print_(' no rows needed to be added')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '43']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tablefromascii'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '34', '37', '40']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tablename'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'asciifile'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'headerfile'},{'id': '8', 'type': 'string', 'children': [], 'value': "''"},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'autoheader'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'autoshape'},{'id': '14', 'type': 'list', 'children': [], 'value': '[]'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'columnnames'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'datatypes'},{'id': '20', 'type': 'list', 'children': [], 'value': '[]'},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '23', 'type': 'string', 'children': [], 'value': "' '"},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'commentmarker'},{'id': '26', 'type': 'string', 'children': [], 'value': "''"},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'firstline'},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'lastline'},{'id': '32', 'type': 'unary_operator', 'children': ['33'], 'value': '-'},{'id': '33', 'type': 'integer', 'children': [], 'value': '1'},{'id': '34', 'type': 'default_parameter', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'readonly'},{'id': '36', 'type': 'True', 'children': []},{'id': '37', 'type': 'default_parameter', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'lockoptions'},{'id': '39', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '40', 'type': 'default_parameter', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ack'},{'id': '42', 'type': 'True', 'children': []},{'id': '43', 'type': 'block', 'children': ['44', '48', '59', '70', '93', '143', '167', '182', '186']},{'id': '44', 'type': 'import_statement', 'children': ['45']},{'id': '45', 'type': 'dotted_name', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '51', 'type': 'call', 'children': ['52', '57']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'expandvars'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'asciifile'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'expanduser'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '70', 'type': 'if_statement', 'children': ['71', '80']},{'id': '71', 'type': 'not_operator', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '78']},{'id': '73', 'type': 'attribute', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '80', 'type': 'block', 'children': ['81', '88']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '%'},{'id': '85', 'type': 'string', 'children': [], 'value': '"File \'%s\' not found"'},{'id': '86', 'type': '()', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '88', 'type': 'raise_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '93', 'type': 'if_statement', 'children': ['94', '97']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '!='},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'headerfile'},{'id': '96', 'type': 'string', 'children': [], 'value': "''"},{'id': '97', 'type': 'block', 'children': ['98', '109', '120']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'expandvars'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'headerfile'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'filename'},{'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': 'os'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'expanduser'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '120', 'type': 'if_statement', 'children': ['121', '130']},{'id': '121', 'type': 'not_operator', 'children': ['122']},{'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': 'os'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '130', 'type': 'block', 'children': ['131', '138']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '%'},{'id': '135', 'type': 'string', 'children': [], 'value': '"File \'%s\' not found"'},{'id': '136', 'type': '()', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '138', 'type': 'raise_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'tab'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150', '151', '152', '153', '154', '155', '156', '157', '158', '161', '164']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'asciifile'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'headerfile'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'tablename'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'autoheader'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'autoshape'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'commentmarker'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'firstline'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'lastline'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': '_columnnames'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'columnnames'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': '_datatypes'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'datatypes'},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': '_oper'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'binary_operator', 'children': ['174', '181'], 'value': '+'},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '+'},{'id': '175', 'type': 'string', 'children': [], 'value': "'Input format: ['"},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'tab'},{'id': '179', 'type': 'identifier', 'children': [], 'value': '_getasciiformat'},{'id': '180', 'type': 'argument_list', 'children': []},{'id': '181', 'type': 'string', 'children': [], 'value': "']'"},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'tab'},{'id': '185', 'type': 'integer', 'children': [], 'value': '0'},{'id': '186', 'type': 'return_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '189', 'type': 'argument_list', 'children': ['190', '191', '194', '197']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'tablename'},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'readonly'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'readonly'},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'lockoptions'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'lockoptions'},{'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'ack'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'ack'}
def tablefromascii(tablename, asciifile, headerfile='', autoheader=False, autoshape=[], columnnames=[], datatypes=[], sep=' ', commentmarker='', firstline=1, lastline=-1, readonly=True, lockoptions='default', ack=True): import os.path filename = os.path.expandvars(asciifile) filename = os.path.expanduser(filename) if not os.path.exists(filename): s = "File '%s' not found" % (filename) raise IOError(s) if headerfile != '': filename = os.path.expandvars(headerfile) filename = os.path.expanduser(filename) if not os.path.exists(filename): s = "File '%s' not found" % (filename) raise IOError(s) tab = table(asciifile, headerfile, tablename, autoheader, autoshape, sep, commentmarker, firstline, lastline, _columnnames=columnnames, _datatypes=datatypes, _oper=1) six.print_('Input format: [' + tab._getasciiformat() + ']') tab = 0 return table(tablename, readonly=readonly, lockoptions=lockoptions, ack=ack)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'makescacoldesc'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'columnname'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'datamanagertype'},{'id': '8', 'type': 'string', 'children': [], 'value': "''"},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'datamanagergroup'},{'id': '11', 'type': 'string', 'children': [], 'value': "''"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '14', 'type': 'integer', 'children': [], 'value': '0'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'maxlen'},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '20', 'type': 'string', 'children': [], 'value': "''"},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'valuetype'},{'id': '23', 'type': 'string', 'children': [], 'value': "''"},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '26', 'type': 'dictionary', 'children': []},{'id': '27', 'type': 'block', 'children': ['28', '32', '44', '69']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'vtype'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'valuetype'},{'id': '32', 'type': 'if_statement', 'children': ['33', '36']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '=='},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'vtype'},{'id': '35', 'type': 'string', 'children': [], 'value': "''"},{'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': 'vtype'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_value_type_name'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'rec2'},{'id': '47', 'type': 'dictionary', 'children': ['48', '51', '54', '57', '60', '63', '66']},{'id': '48', 'type': 'pair', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': "'valueType'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'vtype'},{'id': '51', 'type': 'pair', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'dataManagerType'"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'datamanagertype'},{'id': '54', 'type': 'pair', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'dataManagerGroup'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'datamanagergroup'},{'id': '57', 'type': 'pair', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'option'"},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '60', 'type': 'pair', 'children': ['61', '62']},{'id': '61', 'type': 'string', 'children': [], 'value': "'maxlen'"},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'maxlen'},{'id': '63', 'type': 'pair', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '66', 'type': 'pair', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "'keywords'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'dictionary', 'children': ['71', '74']},{'id': '71', 'type': 'pair', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'columnname'},{'id': '74', 'type': 'pair', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'rec2'}
def makescacoldesc(columnname, value, datamanagertype='', datamanagergroup='', options=0, maxlen=0, comment='', valuetype='', keywords={}): vtype = valuetype if vtype == '': vtype = _value_type_name(value) rec2 = {'valueType': vtype, 'dataManagerType': datamanagertype, 'dataManagerGroup': datamanagergroup, 'option': options, 'maxlen': maxlen, 'comment': comment, 'keywords': keywords} return {'name': columnname, 'desc': rec2}
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '33']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'makearrcoldesc'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'columnname'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '11', 'type': 'list', 'children': [], 'value': '[]'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'datamanagertype'},{'id': '14', 'type': 'string', 'children': [], 'value': "''"},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'datamanagergroup'},{'id': '17', 'type': 'string', 'children': [], 'value': "''"},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'maxlen'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '26', 'type': 'string', 'children': [], 'value': "''"},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'valuetype'},{'id': '29', 'type': 'string', 'children': [], 'value': "''"},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '32', 'type': 'dictionary', 'children': []},{'id': '33', 'type': 'block', 'children': ['34', '38', '50', '70', '104']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'vtype'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'valuetype'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'vtype'},{'id': '41', 'type': 'string', 'children': [], 'value': "''"},{'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': 'vtype'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_value_type_name'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '50', 'type': 'if_statement', 'children': ['51', '57']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '56'], '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': 'identifier', 'children': [], 'value': 'shape'},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'if_statement', 'children': ['59', '62']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': '<='},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'rec2'},{'id': '73', 'type': 'dictionary', 'children': ['74', '77', '80', '83', '86', '89', '92', '95', '98', '101']},{'id': '74', 'type': 'pair', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': "'valueType'"},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'vtype'},{'id': '77', 'type': 'pair', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'dataManagerType'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'datamanagertype'},{'id': '80', 'type': 'pair', 'children': ['81', '82']},{'id': '81', 'type': 'string', 'children': [], 'value': "'dataManagerGroup'"},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'datamanagergroup'},{'id': '83', 'type': 'pair', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': "'ndim'"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '86', 'type': 'pair', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': "'shape'"},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '89', 'type': 'pair', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': "'_c_order'"},{'id': '91', 'type': 'True', 'children': []},{'id': '92', 'type': 'pair', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'option'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '95', 'type': 'pair', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'maxlen'"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'maxlen'},{'id': '98', 'type': 'pair', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'comment'"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '101', 'type': 'pair', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'keywords'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '104', 'type': 'return_statement', 'children': ['105']},{'id': '105', 'type': 'dictionary', 'children': ['106', '109']},{'id': '106', 'type': 'pair', 'children': ['107', '108']},{'id': '107', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'columnname'},{'id': '109', 'type': 'pair', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'rec2'}
def makearrcoldesc(columnname, value, ndim=0, shape=[], datamanagertype='', datamanagergroup='', options=0, maxlen=0, comment='', valuetype='', keywords={}): vtype = valuetype if vtype == '': vtype = _value_type_name(value) if len(shape) > 0: if ndim <= 0: ndim = len(shape) rec2 = {'valueType': vtype, 'dataManagerType': datamanagertype, 'dataManagerGroup': datamanagergroup, 'ndim': ndim, 'shape': shape, '_c_order': True, 'option': options, 'maxlen': maxlen, 'comment': comment, 'keywords': keywords} return {'name': columnname, 'desc': rec2}
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'makedminfo'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tabdesc'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'group_spec'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '18', '46', '53', '179']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'group_spec'},{'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': 'group_spec'},{'id': '17', 'type': 'dictionary', 'children': []},{'id': '18', 'type': 'class_definition', 'children': ['19', '20', '22']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'DMGroup'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'function_definition', 'children': ['24', '25', '27']},{'id': '24', 'type': 'function_name', 'children': [], 'value': '__init__'},{'id': '25', 'type': 'parameters', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'block', 'children': ['28', '34', '40']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '33', 'type': 'list', 'children': [], 'value': '[]'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dm_groups'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'DMGroup'},{'id': '53', 'type': 'for_statement', 'children': ['54', '57', '63']},{'id': '54', 'type': 'pattern_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'tabdesc'},{'id': '63', 'type': 'block', 'children': ['64', '73', '83', '93', '101', '109', '115', '124', '143']},{'id': '64', 'type': 'if_statement', 'children': ['65', '71']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'in'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '67', 'type': 'tuple', 'children': ['68', '69', '70']},{'id': '68', 'type': 'string', 'children': [], 'value': "'_define_hypercolumn_'"},{'id': '69', 'type': 'string', 'children': [], 'value': "'_keywords_'"},{'id': '70', 'type': 'string', 'children': [], 'value': "'_private_keywords_'"},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'continue_statement', 'children': []},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'string', 'children': [], 'value': '"dataManagerGroup"'},{'id': '82', 'type': 'string', 'children': [], 'value': '"StandardStMan"'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': '"dataManagerType"'},{'id': '92', 'type': 'string', 'children': [], 'value': '"StandardStMan"'},{'id': '93', 'type': 'if_statement', 'children': ['94', '96']},{'id': '94', 'type': 'not_operator', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'group'},{'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': 'group'},{'id': '100', 'type': 'string', 'children': [], 'value': '"StandardStMan"'},{'id': '101', 'type': 'if_statement', 'children': ['102', '104']},{'id': '102', 'type': 'not_operator', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '108', 'type': 'string', 'children': [], 'value': '"StandardStMan"'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'dm_group'},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'dm_groups'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '122']},{'id': '117', 'type': 'attribute', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'dm_group'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '124', 'type': 'if_statement', 'children': ['125', '130']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '129'], 'value': 'is'},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'dm_group'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '129', 'type': 'None', 'children': []},{'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': 'dm_group'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'group_spec'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '142', 'type': 'dictionary', 'children': []},{'id': '143', 'type': 'if_statement', 'children': ['144', '149', '156']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '148'], 'value': 'is'},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'dm_group'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '148', 'type': 'None', 'children': []},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'dm_group'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '156', 'type': 'elif_clause', 'children': ['157', '163']},{'id': '157', 'type': 'not_operator', 'children': ['158']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '162'], 'value': '=='},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'dm_group'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'raise_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'binary_operator', 'children': ['169', '173'], 'value': '%'},{'id': '169', 'type': 'concatenated_string', 'children': ['170', '171', '172']},{'id': '170', 'type': 'string', 'children': [], 'value': '"Mismatched dataManagerType \'%s\' "'},{'id': '171', 'type': 'string', 'children': [], 'value': '"for dataManagerGroup \'%s\' "'},{'id': '172', 'type': 'string', 'children': [], 'value': '"Previously, the type was \'%s\'"'},{'id': '173', 'type': 'tuple', 'children': ['174', '175', '176']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'dm_group'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '179', 'type': 'return_statement', 'children': ['180']},{'id': '180', 'type': 'dictionary_comprehension', 'children': ['181', '210']},{'id': '181', 'type': 'pair', 'children': ['182', '188']},{'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '%'},{'id': '183', 'type': 'string', 'children': [], 'value': "'*%d'"},{'id': '184', 'type': '()', 'children': ['185']},{'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '+'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '187', 'type': 'integer', 'children': [], 'value': '1'},{'id': '188', 'type': 'dictionary', 'children': ['189', '194', '199', '202', '207']},{'id': '189', 'type': 'pair', 'children': ['190', '191']},{'id': '190', 'type': 'string', 'children': [], 'value': "'COLUMNS'"},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'dm_group'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '194', 'type': 'pair', 'children': ['195', '196']},{'id': '195', 'type': 'string', 'children': [], 'value': "'TYPE'"},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'dm_group'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '199', 'type': 'pair', 'children': ['200', '201']},{'id': '200', 'type': 'string', 'children': [], 'value': "'NAME'"},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '202', 'type': 'pair', 'children': ['203', '204']},{'id': '203', 'type': 'string', 'children': [], 'value': "'SPEC'"},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'dm_group'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '207', 'type': 'pair', 'children': ['208', '209']},{'id': '208', 'type': 'string', 'children': [], 'value': "'SEQNR'"},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '210', 'type': 'for_in_clause', 'children': ['211', '216']},{'id': '211', 'type': 'pattern_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '213', 'type': 'tuple_pattern', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'dm_group'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'dm_groups'}
def makedminfo(tabdesc, group_spec=None): if group_spec is None: group_spec = {} class DMGroup(object): def __init__(self): self.columns = [] self.type = None self.spec = None dm_groups = defaultdict(DMGroup) for c, d in six.iteritems(tabdesc): if c in ('_define_hypercolumn_', '_keywords_', '_private_keywords_'): continue group = d.get("dataManagerGroup", "StandardStMan") type_ = d.get("dataManagerType", "StandardStMan") if not group: group = "StandardStMan" if not type_: type_ = "StandardStMan" dm_group = dm_groups[group] dm_group.columns.append(c) if dm_group.spec is None: dm_group.spec = group_spec.get(group, {}) if dm_group.type is None: dm_group.type = type_ elif not dm_group.type == type_: raise ValueError("Mismatched dataManagerType '%s' " "for dataManagerGroup '%s' " "Previously, the type was '%s'" % (type_, group, dm_group.type)) return { '*%d'%(i+1): { 'COLUMNS': dm_group.columns, 'TYPE': dm_group.type, 'NAME': group, 'SPEC' : dm_group.spec, 'SEQNR': i } for i, (group, dm_group) in enumerate(six.iteritems(dm_groups)) }
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'attrgetrow'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '27', '38', '64', '90']},{'id': '11', 'type': 'if_statement', 'children': ['12', '18']},{'id': '12', 'type': 'not_operator', 'children': ['13']},{'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': 'key'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_attrgetrow'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'rownrs'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'attrfindrows'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36', '37']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '38', 'type': 'if_statement', 'children': ['39', '45']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '44'], 'value': '=='},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'rownrs'},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'raise_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'binary_operator', 'children': ['51', '60'], 'value': '+'},{'id': '51', 'type': 'binary_operator', 'children': ['52', '59'], 'value': '+'},{'id': '52', 'type': 'binary_operator', 'children': ['53', '58'], 'value': '+'},{'id': '53', 'type': 'binary_operator', 'children': ['54', '57'], 'value': '+'},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '+'},{'id': '55', 'type': 'string', 'children': [], 'value': '"Image attribute "'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'string', 'children': [], 'value': '" in group "'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '59', 'type': 'string', 'children': [], 'value': '" has no matches for value "'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '64', 'type': 'if_statement', 'children': ['65', '71']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '70'], 'value': '>'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'rownrs'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'raise_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'binary_operator', 'children': ['77', '86'], 'value': '+'},{'id': '77', 'type': 'binary_operator', 'children': ['78', '85'], 'value': '+'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '84'], 'value': '+'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '83'], 'value': '+'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '+'},{'id': '81', 'type': 'string', 'children': [], 'value': '"Image attribute "'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '83', 'type': 'string', 'children': [], 'value': '" in group "'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '85', 'type': 'string', 'children': [], 'value': '" has multiple matches for value "'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_attrgetrow'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'rownrs'},{'id': '99', 'type': 'integer', 'children': [], 'value': '0'}
def attrgetrow(self, groupname, key, value=None): if not isinstance(key, str): return self._attrgetrow(groupname, key) rownrs = self.attrfindrows(groupname, key, value) if len(rownrs) == 0: raise IndexError("Image attribute " + key + " in group " + groupname + " has no matches for value " + str(value)) if len(rownrs) > 1: raise IndexError("Image attribute " + key + " in group " + groupname + " has multiple matches for value " + str(value)) return self._attrgetrow(groupname, rownrs[0])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'substitute'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'objlist'},{'id': '7', 'type': 'tuple', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'globals'},{'id': '10', 'type': 'dictionary', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '13', 'type': 'dictionary', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '26', '30', '34', '38', '42', '46', '50', '54', '58', '267', '293']},{'id': '15', 'type': 'if_statement', 'children': ['16', '18']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'locals'},{'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': 'locals'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'getlocals'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'integer', 'children': [], 'value': '3'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'backslash'},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'dollar'},{'id': '33', 'type': 'False', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'nparen'},{'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': 'name'},{'id': '41', 'type': 'string', 'children': [], 'value': "''"},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'evalstr'},{'id': '45', 'type': 'string', 'children': [], 'value': "''"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'squote'},{'id': '49', 'type': 'False', 'children': []},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dquote'},{'id': '53', 'type': 'False', 'children': []},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '57', 'type': 'string', 'children': [], 'value': "''"},{'id': '58', 'type': 'for_statement', 'children': ['59', '60', '61']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '61', 'type': 'block', 'children': ['62', '74', '150', '176', '243', '258']},{'id': '62', 'type': 'if_statement', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'backslash'},{'id': '64', 'type': 'block', 'children': ['65', '69', '73']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'augmented_assignment', 'children': ['67', '68'], 'value': '+='},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'backslash'},{'id': '72', 'type': 'False', 'children': []},{'id': '73', 'type': 'continue_statement', 'children': []},{'id': '74', 'type': 'if_statement', 'children': ['75', '80']},{'id': '75', 'type': 'boolean_operator', 'children': ['76', '77'], 'value': 'and'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dollar'},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': '=='},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'nparen'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'block', 'children': ['81', '103', '118', '136', '146']},{'id': '81', 'type': 'if_statement', 'children': ['82', '97']},{'id': '82', 'type': 'boolean_operator', 'children': ['83', '92'], 'value': 'or'},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '87'], 'value': 'or'},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '=='},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '86', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '87', 'type': '()', 'children': ['88']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90', '91'], 'value': '<='},{'id': '89', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '91', 'type': 'string', 'children': [], 'value': "'z'"},{'id': '92', 'type': '()', 'children': ['93']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95', '96'], 'value': '<='},{'id': '94', 'type': 'string', 'children': [], 'value': "'A'"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '96', 'type': 'string', 'children': [], 'value': "'Z'"},{'id': '97', 'type': 'block', 'children': ['98', '102']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'augmented_assignment', 'children': ['100', '101'], 'value': '+='},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '102', 'type': 'continue_statement', 'children': []},{'id': '103', 'type': 'if_statement', 'children': ['104', '112']},{'id': '104', 'type': 'boolean_operator', 'children': ['105', '109'], 'value': 'and'},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107', '108'], 'value': '<='},{'id': '106', 'type': 'string', 'children': [], 'value': "'0'"},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '108', 'type': 'string', 'children': [], 'value': "'9'"},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '!='},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '111', 'type': 'string', 'children': [], 'value': "''"},{'id': '112', 'type': 'block', 'children': ['113', '117']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'augmented_assignment', 'children': ['115', '116'], 'value': '+='},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '117', 'type': 'continue_statement', 'children': []},{'id': '118', 'type': 'if_statement', 'children': ['119', '126']},{'id': '119', 'type': 'boolean_operator', 'children': ['120', '123'], 'value': 'and'},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '=='},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '122', 'type': 'string', 'children': [], 'value': "'('"},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '=='},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '125', 'type': 'string', 'children': [], 'value': "''"},{'id': '126', 'type': 'block', 'children': ['127', '131', '135']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'nparen'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'evalstr'},{'id': '134', 'type': 'string', 'children': [], 'value': "''"},{'id': '135', 'type': 'continue_statement', 'children': []},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'augmented_assignment', 'children': ['138', '139'], 'value': '+='},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'substitutename'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143', '144', '145']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'objlist'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'globals'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dollar'},{'id': '149', 'type': 'False', 'children': []},{'id': '150', 'type': 'if_statement', 'children': ['151', '157', '163']},{'id': '151', 'type': 'boolean_operator', 'children': ['152', '155'], 'value': 'and'},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': '=='},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '154', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '155', 'type': 'not_operator', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'squote'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'dquote'},{'id': '161', 'type': 'not_operator', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'dquote'},{'id': '163', 'type': 'elif_clause', 'children': ['164', '170']},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '168'], 'value': 'and'},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '=='},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '167', 'type': 'string', 'children': [], 'value': '"\'"'},{'id': '168', 'type': 'not_operator', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'dquote'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'squote'},{'id': '174', 'type': 'not_operator', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'squote'},{'id': '176', 'type': 'if_statement', 'children': ['177', '182']},{'id': '177', 'type': 'boolean_operator', 'children': ['178', '180'], 'value': 'and'},{'id': '178', 'type': 'not_operator', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'dquote'},{'id': '180', 'type': 'not_operator', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'squote'},{'id': '182', 'type': 'block', 'children': ['183', '229']},{'id': '183', 'type': 'if_statement', 'children': ['184', '187']},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': '>'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'nparen'},{'id': '186', 'type': 'integer', 'children': [], 'value': '0'},{'id': '187', 'type': 'block', 'children': ['188', '224', '228']},{'id': '188', 'type': 'if_statement', 'children': ['189', '192', '197']},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': '=='},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '191', 'type': 'string', 'children': [], 'value': "'('"},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'augmented_assignment', 'children': ['195', '196'], 'value': '+='},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'nparen'},{'id': '196', 'type': 'integer', 'children': [], 'value': '1'},{'id': '197', 'type': 'elif_clause', 'children': ['198', '201']},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': '=='},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '200', 'type': 'string', 'children': [], 'value': "')'"},{'id': '201', 'type': 'block', 'children': ['202', '206']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'augmented_assignment', 'children': ['204', '205'], 'value': '-='},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'nparen'},{'id': '205', 'type': 'integer', 'children': [], 'value': '1'},{'id': '206', 'type': 'if_statement', 'children': ['207', '210']},{'id': '207', 'type': 'comparison_operator', 'children': ['208', '209'], 'value': '=='},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'nparen'},{'id': '209', 'type': 'integer', 'children': [], 'value': '0'},{'id': '210', 'type': 'block', 'children': ['211', '220']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'augmented_assignment', 'children': ['213', '214'], 'value': '+='},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'substituteexpr'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218', '219']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'evalstr'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'globals'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'dollar'},{'id': '223', 'type': 'False', 'children': []},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'augmented_assignment', 'children': ['226', '227'], 'value': '+='},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'evalstr'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '228', 'type': 'continue_statement', 'children': []},{'id': '229', 'type': 'if_statement', 'children': ['230', '233']},{'id': '230', 'type': 'comparison_operator', 'children': ['231', '232'], 'value': '=='},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '232', 'type': 'string', 'children': [], 'value': "'$'"},{'id': '233', 'type': 'block', 'children': ['234', '238', '242']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'dollar'},{'id': '237', 'type': 'True', 'children': []},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '241', 'type': 'string', 'children': [], 'value': "''"},{'id': '242', 'type': 'continue_statement', 'children': []},{'id': '243', 'type': 'if_statement', 'children': ['244', '247', '252']},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': '=='},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'nparen'},{'id': '246', 'type': 'integer', 'children': [], 'value': '0'},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'augmented_assignment', 'children': ['250', '251'], 'value': '+='},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '252', 'type': 'else_clause', 'children': ['253']},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'augmented_assignment', 'children': ['256', '257'], 'value': '+='},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'evalstr'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '258', 'type': 'if_statement', 'children': ['259', '262']},{'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': '=='},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '261', 'type': 'string', 'children': [], 'value': "'\\\\'"},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'backslash'},{'id': '266', 'type': 'True', 'children': []},{'id': '267', 'type': 'if_statement', 'children': ['268', '269', '280']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'dollar'},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'augmented_assignment', 'children': ['272', '273'], 'value': '+='},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'substitutename'},{'id': '275', 'type': 'argument_list', 'children': ['276', '277', '278', '279']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'objlist'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'globals'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '280', 'type': 'else_clause', 'children': ['281']},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'if_statement', 'children': ['283', '286']},{'id': '283', 'type': 'comparison_operator', 'children': ['284', '285'], 'value': '>'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'nparen'},{'id': '285', 'type': 'integer', 'children': [], 'value': '0'},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'augmented_assignment', 'children': ['289', '290'], 'value': '+='},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '290', 'type': 'binary_operator', 'children': ['291', '292'], 'value': '+'},{'id': '291', 'type': 'string', 'children': [], 'value': "'$('"},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'evalstr'},{'id': '293', 'type': 'return_statement', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'out'}
def substitute(s, objlist=(), globals={}, locals={}): if not locals: locals = getlocals(3) backslash = False dollar = False nparen = 0 name = '' evalstr = '' squote = False dquote = False out = '' for tmp in s: if backslash: out += tmp backslash = False continue if dollar and nparen == 0: if tmp == '_' or ('a' <= tmp <= 'z') or ('A' <= tmp <= 'Z'): name += tmp continue if '0' <= tmp <= '9' and name != '': name += tmp continue if tmp == '(' and name == '': nparen = 1 evalstr = '' continue out += substitutename(name, objlist, globals, locals) dollar = False if tmp == '"' and not squote: dquote = not dquote elif tmp == "'" and not dquote: squote = not squote if not dquote and not squote: if nparen > 0: if tmp == '(': nparen += 1 elif tmp == ')': nparen -= 1 if nparen == 0: out += substituteexpr(evalstr, globals, locals) dollar = False evalstr += tmp continue if tmp == '$': dollar = True name = '' continue if nparen == 0: out += tmp else: evalstr += tmp if tmp == '\\': backslash = True if dollar: out += substitutename(name, objlist, globals, locals) else: if nparen > 0: out += '$(' + evalstr return out
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'columnnames'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '8', 'type': 'string', 'children': [], 'value': "''"},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '20']},{'id': '13', 'type': 'import_from_statement', 'children': ['14', '18']},{'id': '14', 'type': 'relative_import', 'children': ['15', '16']},{'id': '15', 'type': 'import_prefix', 'children': []},{'id': '16', 'type': 'dotted_name', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'tableiter'},{'id': '18', 'type': 'dotted_name', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'tableiter'},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'tableiter'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25', '26', '27']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'columnnames'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort'}
def iter(self, columnnames, order='', sort=True): from .tableiter import tableiter return tableiter(self, columnnames, order, sort)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'index'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'columnnames'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '17']},{'id': '10', 'type': 'import_from_statement', 'children': ['11', '15']},{'id': '11', 'type': 'relative_import', 'children': ['12', '13']},{'id': '12', 'type': 'import_prefix', 'children': []},{'id': '13', 'type': 'dotted_name', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'tableindex'},{'id': '15', 'type': 'dotted_name', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'tableindex'},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'tableindex'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'columnnames'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort'}
def index(self, columnnames, sort=True): from .tableindex import tableindex return tableindex(self, columnnames, sort)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rownumbers'},{'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': 'table'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '23']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_rownumbers'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Table'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_rownumbers'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'table'}
def rownumbers(self, table=None): if table is None: return self._rownumbers(Table()) return self._rownumbers(table)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'showstructure'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'dataman'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'subtable'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_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': '_showstructure'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25', '26', '27']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dataman'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'subtable'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort'}
def showstructure(self, dataman=True, column=True, subtable=False, sort=False): return self._showstructure(dataman, column, subtable, sort)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'query'},{'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': 'query'},{'id': '7', 'type': 'string', 'children': [], 'value': "''"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '10', 'type': 'string', 'children': [], 'value': "''"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sortlist'},{'id': '13', 'type': 'string', 'children': [], 'value': "''"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'columns'},{'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': 'style'},{'id': '25', 'type': 'string', 'children': [], 'value': "'Python'"},{'id': '26', 'type': 'block', 'children': ['27', '53', '57', '64', '68', '77', '86', '97', '108', '117']},{'id': '27', 'type': 'if_statement', 'children': ['28', '45']},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '42'], 'value': 'and'},{'id': '29', 'type': 'boolean_operator', 'children': ['30', '38', '39'], 'value': 'and'},{'id': '30', 'type': 'boolean_operator', 'children': ['31', '36'], 'value': 'and'},{'id': '31', 'type': 'boolean_operator', 'children': ['32', '34'], 'value': 'and'},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '34', 'type': 'not_operator', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sortlist'},{'id': '36', 'type': 'not_operator', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '38', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '<='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '<='},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'raise_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '+'},{'id': '51', 'type': 'string', 'children': [], 'value': "'No selection done (arguments query, '"},{'id': '52', 'type': 'string', 'children': [], 'value': "'sortlist, columns, limit, and offset are empty)'"},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '56', 'type': 'string', 'children': [], 'value': "'select '"},{'id': '57', 'type': 'if_statement', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'augmented_assignment', 'children': ['62', '63'], 'value': '+='},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'augmented_assignment', 'children': ['66', '67'], 'value': '+='},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '67', 'type': 'string', 'children': [], 'value': "' from $1'"},{'id': '68', 'type': 'if_statement', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'augmented_assignment', 'children': ['73', '74'], 'value': '+='},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '+'},{'id': '75', 'type': 'string', 'children': [], 'value': "' where '"},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '77', 'type': 'if_statement', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sortlist'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'augmented_assignment', 'children': ['82', '83'], 'value': '+='},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '+'},{'id': '84', 'type': 'string', 'children': [], 'value': "' orderby '"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sortlist'},{'id': '86', 'type': 'if_statement', 'children': ['87', '90']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '>'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'augmented_assignment', 'children': ['93', '94'], 'value': '+='},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '%'},{'id': '95', 'type': 'string', 'children': [], 'value': "' limit %d'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '97', 'type': 'if_statement', 'children': ['98', '101']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': '>'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'augmented_assignment', 'children': ['104', '105'], 'value': '+='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '%'},{'id': '106', 'type': 'string', 'children': [], 'value': "' offset %d'"},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '108', 'type': 'if_statement', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'augmented_assignment', 'children': ['113', '114'], 'value': '+='},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '+'},{'id': '115', 'type': 'string', 'children': [], 'value': "' giving '"},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'tablecommand'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122', '123']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '123', 'type': 'list', 'children': ['124'], 'value': '[self]'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}
def query(self, query='', name='', sortlist='', columns='', limit=0, offset=0, style='Python'): if not query and not sortlist and not columns and \ limit <= 0 and offset <= 0: raise ValueError('No selection done (arguments query, ' + 'sortlist, columns, limit, and offset are empty)') command = 'select ' if columns: command += columns command += ' from $1' if query: command += ' where ' + query if sortlist: command += ' orderby ' + sortlist if limit > 0: command += ' limit %d' % limit if offset > 0: command += ' offset %d' % offset if name: command += ' giving ' + name return tablecommand(command, style, [self])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sortlist'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '8', 'type': 'string', 'children': [], 'value': "''"},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '11', 'type': 'integer', 'children': [], 'value': '0'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '14', 'type': 'integer', 'children': [], 'value': '0'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '17', 'type': 'string', 'children': [], 'value': "'Python'"},{'id': '18', 'type': 'block', 'children': ['19', '25', '36', '47', '56']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '+'},{'id': '23', 'type': 'string', 'children': [], 'value': "'select from $1 orderby '"},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sortlist'},{'id': '25', 'type': 'if_statement', 'children': ['26', '29']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '>'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'augmented_assignment', 'children': ['32', '33'], 'value': '+='},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'},{'id': '34', 'type': 'string', 'children': [], 'value': "' limit %d'"},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '>'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'augmented_assignment', 'children': ['43', '44'], 'value': '+='},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '%'},{'id': '45', 'type': 'string', 'children': [], 'value': "' offset %d'"},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '47', 'type': 'if_statement', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'augmented_assignment', 'children': ['52', '53'], 'value': '+='},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '+'},{'id': '54', 'type': 'string', 'children': [], 'value': "' giving '"},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'tablecommand'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61', '62']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '62', 'type': 'list', 'children': ['63'], 'value': '[self]'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort(self, sortlist, name='', limit=0, offset=0, style='Python'): command = 'select from $1 orderby ' + sortlist if limit > 0: command += ' limit %d' % limit if offset > 0: command += ' offset %d' % offset if name: command += ' giving ' + name return tablecommand(command, style, [self])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'browse'},{'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': 'wait'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'id': '10', 'type': 'string', 'children': [], 'value': '"/tmp/seltable"'},{'id': '11', 'type': 'block', 'children': ['12', '15']},{'id': '12', 'type': 'import_statement', 'children': ['13']},{'id': '13', 'type': 'dotted_name', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '15', 'type': 'if_statement', 'children': ['16', '24', '211']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '23'], 'value': '=='},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': "'test `which casabrowser`x != x'"},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'block', 'children': ['25', '29', '33', '45', '72', '78', '84']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'waitstr1'},{'id': '28', 'type': 'string', 'children': [], 'value': '""'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'waitstr2'},{'id': '32', 'type': 'string', 'children': [], 'value': '"foreground ..."'},{'id': '33', 'type': 'if_statement', 'children': ['34', '36']},{'id': '34', 'type': 'not_operator', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '36', 'type': 'block', 'children': ['37', '41']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'waitstr1'},{'id': '40', 'type': 'string', 'children': [], 'value': '" &"'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'waitstr2'},{'id': '44', 'type': 'string', 'children': [], 'value': '"background ..."'},{'id': '45', 'type': 'if_statement', 'children': ['46', '51', '61']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'iswritable'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '+'},{'id': '59', 'type': 'string', 'children': [], 'value': '"Flushing data and starting casabrowser in the "'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'waitstr2'},{'id': '61', 'type': 'else_clause', 'children': ['62']},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '+'},{'id': '70', 'type': 'string', 'children': [], 'value': '"Starting casabrowser in the "'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'waitstr2'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'unlock'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'if_statement', 'children': ['85', '101', '117', '186']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '100'], 'value': '=='},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'binary_operator', 'children': ['92', '99'], 'value': '+'},{'id': '92', 'type': 'binary_operator', 'children': ['93', '94'], 'value': '+'},{'id': '93', 'type': 'string', 'children': [], 'value': "'test -e '"},{'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': 'name'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'string', 'children': [], 'value': "'/table.dat'"},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'binary_operator', 'children': ['109', '116'], 'value': '+'},{'id': '109', 'type': 'binary_operator', 'children': ['110', '111'], 'value': '+'},{'id': '110', 'type': 'string', 'children': [], 'value': "'casabrowser '"},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '115', 'type': 'argument_list', 'children': []},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'waitstr1'},{'id': '117', 'type': 'elif_clause', 'children': ['118', '124']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '123'], 'value': '>'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'id': '123', 'type': 'integer', 'children': [], 'value': '0'},{'id': '124', 'type': 'block', 'children': ['125', '134', '141', '152']},{'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': 'six'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '+'},{'id': '132', 'type': 'string', 'children': [], 'value': '" making a persistent copy in table "'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'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': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'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': 'os'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'binary_operator', 'children': ['148', '151'], 'value': '+'},{'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '+'},{'id': '149', 'type': 'string', 'children': [], 'value': "'casabrowser '"},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'waitstr1'},{'id': '152', 'type': 'if_statement', 'children': ['153', '154', '173']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '154', 'type': 'block', 'children': ['155', '161', '168']},{'id': '155', 'type': 'import_from_statement', 'children': ['156', '159']},{'id': '156', 'type': 'dotted_name', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'casacore'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'tables'},{'id': '159', 'type': 'dotted_name', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'tabledelete'},{'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': 'six'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': '" finished browsing"'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'tabledelete'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'id': '173', 'type': 'else_clause', 'children': ['174']},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'binary_operator', 'children': ['182', '185'], 'value': '+'},{'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '+'},{'id': '183', 'type': 'string', 'children': [], 'value': '" after browsing use tabledelete(\'"'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'id': '185', 'type': 'string', 'children': [], 'value': '"\') to delete the copy"'},{'id': '186', 'type': 'else_clause', 'children': ['187']},{'id': '187', 'type': 'block', 'children': ['188', '195', '204']},{'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': 'six'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'string', 'children': [], 'value': '"Cannot browse because the table is in memory only"'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '+'},{'id': '202', 'type': 'string', 'children': [], 'value': '"You can browse a (shallow) persistent copy "'},{'id': '203', 'type': 'string', 'children': [], 'value': '"of the table like: "'},{'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': 'six'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'string', 'children': [], 'value': '" t.browse(True, \'/tmp/tab1\')"'},{'id': '211', 'type': 'else_clause', 'children': ['212']},{'id': '212', 'type': 'block', 'children': ['213', '229', '235', '238', '244', '249', '260', '267']},{'id': '213', 'type': 'try_statement', 'children': ['214', '218']},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'import_statement', 'children': ['216']},{'id': '216', 'type': 'dotted_name', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'wxPython'},{'id': '218', 'type': 'except_clause', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '220', 'type': 'block', 'children': ['221', '228']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'string', 'children': [], 'value': "'casabrowser nor wxPython can be found'"},{'id': '228', 'type': 'return_statement', 'children': []},{'id': '229', 'type': 'import_from_statement', 'children': ['230', '233']},{'id': '230', 'type': 'dotted_name', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'wxPython'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'wx'},{'id': '233', 'type': 'dotted_name', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'wxPySimpleApp'},{'id': '235', 'type': 'import_statement', 'children': ['236']},{'id': '236', 'type': 'dotted_name', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'wxPySimpleApp'},{'id': '243', 'type': 'argument_list', 'children': []},{'id': '244', 'type': 'import_from_statement', 'children': ['245', '247']},{'id': '245', 'type': 'dotted_name', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'wxtablebrowser'},{'id': '247', 'type': 'dotted_name', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'CasaTestFrame'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'frame'},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'CasaTestFrame'},{'id': '254', 'type': 'argument_list', 'children': ['255', '256', '259']},{'id': '255', 'type': 'None', 'children': []},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'},{'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': 'frame'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'Show'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'True', 'children': []},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'MainLoop'},{'id': '272', 'type': 'argument_list', 'children': []}
def browse(self, wait=True, tempname="/tmp/seltable"): import os if os.system('test `which casabrowser`x != x') == 0: waitstr1 = "" waitstr2 = "foreground ..." if not wait: waitstr1 = " &" waitstr2 = "background ..." if self.iswritable(): six.print_("Flushing data and starting casabrowser in the " + waitstr2) else: six.print_("Starting casabrowser in the " + waitstr2) self.flush() self.unlock() if os.system('test -e ' + self.name() + '/table.dat') == 0: os.system('casabrowser ' + self.name() + waitstr1) elif len(tempname) > 0: six.print_(" making a persistent copy in table " + tempname) self.copy(tempname) os.system('casabrowser ' + tempname + waitstr1) if wait: from casacore.tables import tabledelete six.print_(" finished browsing") tabledelete(tempname) else: six.print_(" after browsing use tabledelete('" + tempname + "') to delete the copy") else: six.print_("Cannot browse because the table is in memory only") six.print_("You can browse a (shallow) persistent copy " + "of the table like: ") six.print_(" t.browse(True, '/tmp/tab1')") else: try: import wxPython except ImportError: six.print_('casabrowser nor wxPython can be found') return from wxPython.wx import wxPySimpleApp import sys app = wxPySimpleApp() from wxtablebrowser import CasaTestFrame frame = CasaTestFrame(None, sys.stdout, self) frame.Show(True) app.MainLoop()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'view'},{'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': 'wait'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'id': '10', 'type': 'string', 'children': [], 'value': '"/tmp/seltable"'},{'id': '11', 'type': 'block', 'children': ['12', '15', '19', '29', '246']},{'id': '12', 'type': 'import_statement', 'children': ['13']},{'id': '13', 'type': 'dotted_name', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'viewed'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '22', 'type': 'subscript', 'children': ['23', '28']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '29', 'type': 'if_statement', 'children': ['30', '37']},{'id': '30', 'type': 'boolean_operator', 'children': ['31', '34'], 'value': 'or'},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '=='},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '33', 'type': 'string', 'children': [], 'value': '"Measurement Set"'},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '=='},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '36', 'type': 'string', 'children': [], 'value': '"Image"'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'if_statement', 'children': ['39', '47']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '46'], 'value': '=='},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': "'test -x `which casaviewer` > /dev/null 2>&1'"},{'id': '46', 'type': 'integer', 'children': [], 'value': '0'},{'id': '47', 'type': 'block', 'children': ['48', '52', '56', '68', '97', '103', '109']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'waitstr1'},{'id': '51', 'type': 'string', 'children': [], 'value': '""'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'waitstr2'},{'id': '55', 'type': 'string', 'children': [], 'value': '"foreground ..."'},{'id': '56', 'type': 'if_statement', 'children': ['57', '59']},{'id': '57', 'type': 'not_operator', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '59', 'type': 'block', 'children': ['60', '64']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'waitstr1'},{'id': '63', 'type': 'string', 'children': [], 'value': '" &"'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'waitstr2'},{'id': '67', 'type': 'string', 'children': [], 'value': '"background ..."'},{'id': '68', 'type': 'if_statement', 'children': ['69', '74', '86']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'iswritable'},{'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', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'binary_operator', 'children': ['82', '85'], 'value': '+'},{'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '+'},{'id': '83', 'type': 'string', 'children': [], 'value': '"Flushing data and starting casaviewer "'},{'id': '84', 'type': 'string', 'children': [], 'value': '"in the "'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'waitstr2'},{'id': '86', 'type': 'else_clause', 'children': ['87']},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '+'},{'id': '95', 'type': 'string', 'children': [], 'value': '"Starting casaviewer in the "'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'waitstr2'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'unlock'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'if_statement', 'children': ['110', '126', '146', '219']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '125'], 'value': '=='},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'binary_operator', 'children': ['117', '124'], 'value': '+'},{'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '+'},{'id': '118', 'type': 'string', 'children': [], 'value': "'test -e '"},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'string', 'children': [], 'value': "'/table.dat'"},{'id': '125', 'type': 'integer', 'children': [], 'value': '0'},{'id': '126', 'type': 'block', 'children': ['127', '142']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '141'], 'value': '+'},{'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '+'},{'id': '135', 'type': 'string', 'children': [], 'value': "'casaviewer '"},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '140', 'type': 'argument_list', 'children': []},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'waitstr1'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'viewed'},{'id': '145', 'type': 'True', 'children': []},{'id': '146', 'type': 'elif_clause', 'children': ['147', '153']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '152'], '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': 'identifier', 'children': [], 'value': 'tempname'},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'block', 'children': ['154', '163', '170', '181', '185']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '+'},{'id': '161', 'type': 'string', 'children': [], 'value': '" making a persistent copy in table "'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'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': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'binary_operator', 'children': ['177', '180'], 'value': '+'},{'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '+'},{'id': '178', 'type': 'string', 'children': [], 'value': "'casaviewer '"},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'waitstr1'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'viewed'},{'id': '184', 'type': 'True', 'children': []},{'id': '185', 'type': 'if_statement', 'children': ['186', '187', '206']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '187', 'type': 'block', 'children': ['188', '194', '201']},{'id': '188', 'type': 'import_from_statement', 'children': ['189', '192']},{'id': '189', 'type': 'dotted_name', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'casacore'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'tables'},{'id': '192', 'type': 'dotted_name', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'tabledelete'},{'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': 'six'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'string', 'children': [], 'value': '" finished viewing"'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'tabledelete'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'id': '206', 'type': 'else_clause', 'children': ['207']},{'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': 'six'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'binary_operator', 'children': ['215', '218'], 'value': '+'},{'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '+'},{'id': '216', 'type': 'string', 'children': [], 'value': '" after viewing use tabledelete(\'"'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'tempname'},{'id': '218', 'type': 'string', 'children': [], 'value': '"\') to delete the copy"'},{'id': '219', 'type': 'else_clause', 'children': ['220']},{'id': '220', 'type': 'block', 'children': ['221', '230', '239']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '+'},{'id': '228', 'type': 'string', 'children': [], 'value': '"Cannot browse because the table is "'},{'id': '229', 'type': 'string', 'children': [], 'value': '"in memory only."'},{'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': 'six'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'binary_operator', 'children': ['237', '238'], 'value': '+'},{'id': '237', 'type': 'string', 'children': [], 'value': '"You can browse a (shallow) persistent "'},{'id': '238', 'type': 'string', 'children': [], 'value': '"copy of the table like:"'},{'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': 'six'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'print_'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'string', 'children': [], 'value': '" t.view(True, \'/tmp/tab1\')"'},{'id': '246', 'type': 'if_statement', 'children': ['247', '249']},{'id': '247', 'type': 'not_operator', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'viewed'},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'browse'},{'id': '255', 'type': 'argument_list', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'tempname'}
def view(self, wait=True, tempname="/tmp/seltable"): import os viewed = False type = self.info()["type"] if type == "Measurement Set" or type == "Image": if os.system('test -x `which casaviewer` > /dev/null 2>&1') == 0: waitstr1 = "" waitstr2 = "foreground ..." if not wait: waitstr1 = " &" waitstr2 = "background ..." if self.iswritable(): six.print_("Flushing data and starting casaviewer " + "in the " + waitstr2) else: six.print_("Starting casaviewer in the " + waitstr2) self.flush() self.unlock() if os.system('test -e ' + self.name() + '/table.dat') == 0: os.system('casaviewer ' + self.name() + waitstr1) viewed = True elif len(tempname) > 0: six.print_(" making a persistent copy in table " + tempname) self.copy(tempname) os.system('casaviewer ' + tempname + waitstr1) viewed = True if wait: from casacore.tables import tabledelete six.print_(" finished viewing") tabledelete(tempname) else: six.print_(" after viewing use tabledelete('" + tempname + "') to delete the copy") else: six.print_("Cannot browse because the table is " + "in memory only.") six.print_("You can browse a (shallow) persistent " + "copy of the table like:") six.print_(" t.view(True, '/tmp/tab1')") if not viewed: self.browse(wait, tempname)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_repr_html_'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '56', '60', '64', '112', '131', '135', '156']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '9', 'type': 'string', 'children': [], 'value': '"<table class=\'taqltable\' style=\'overflow-x:auto\'>\\n"'},{'id': '10', 'type': 'if_statement', 'children': ['11', '31']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': '()', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'list_comprehension', 'children': ['17', '24']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '23'], 'value': '=='},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'colname'},{'id': '20', 'type': 'slice', 'children': ['21', '22']},{'id': '21', 'type': 'colon', 'children': []},{'id': '22', 'type': 'integer', 'children': [], 'value': '4'},{'id': '23', 'type': 'string', 'children': [], 'value': '"Col_"'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'colname'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'colnames'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '36', '52']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'augmented_assignment', 'children': ['34', '35'], 'value': '+='},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '35', 'type': 'string', 'children': [], 'value': '"<tr>"'},{'id': '36', 'type': 'for_statement', 'children': ['37', '38', '43']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'colname'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'colnames'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'augmented_assignment', 'children': ['46', '47'], 'value': '+='},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '51'], 'value': '+'},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '+'},{'id': '49', 'type': 'string', 'children': [], 'value': '"<th><b>"'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'colname'},{'id': '51', 'type': 'string', 'children': [], 'value': '"</b></th>"'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'augmented_assignment', 'children': ['54', '55'], 'value': '+='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '55', 'type': 'string', 'children': [], 'value': '"</tr>"'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'cropped'},{'id': '59', 'type': 'False', 'children': []},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'rowcount'},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'for_statement', 'children': ['65', '66', '67']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'block', 'children': ['68', '81', '85', '89', '98', '102']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'rowout'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': '_format_row'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '80']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'colnames'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'augmented_assignment', 'children': ['83', '84'], 'value': '+='},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'rowcount'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'augmented_assignment', 'children': ['87', '88'], 'value': '+='},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'rowout'},{'id': '89', 'type': 'if_statement', 'children': ['90', '93']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'in'},{'id': '91', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'rowout'},{'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': 'out'},{'id': '97', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'augmented_assignment', 'children': ['100', '101'], 'value': '+='},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '101', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '102', 'type': 'if_statement', 'children': ['103', '106']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '>='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'rowcount'},{'id': '105', 'type': 'integer', 'children': [], 'value': '20'},{'id': '106', 'type': 'block', 'children': ['107', '111']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'cropped'},{'id': '110', 'type': 'True', 'children': []},{'id': '111', 'type': 'break_statement', 'children': []},{'id': '112', 'type': 'if_statement', 'children': ['113', '121']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '120'], 'value': '=='},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '116', 'type': 'slice', 'children': ['117', '119']},{'id': '117', 'type': 'unary_operator', 'children': ['118'], 'value': '-'},{'id': '118', 'type': 'integer', 'children': [], 'value': '2'},{'id': '119', 'type': 'colon', 'children': []},{'id': '120', 'type': 'string', 'children': [], 'value': '"\\n\\n"'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '127', 'type': 'slice', 'children': ['128', '129']},{'id': '128', 'type': 'colon', 'children': []},{'id': '129', 'type': 'unary_operator', 'children': ['130'], 'value': '-'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'augmented_assignment', 'children': ['133', '134'], 'value': '+='},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '134', 'type': 'string', 'children': [], 'value': '"</table>"'},{'id': '135', 'type': 'if_statement', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'cropped'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'augmented_assignment', 'children': ['140', '141'], 'value': '+='},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '141', 'type': '()', 'children': ['142']},{'id': '142', 'type': 'binary_operator', 'children': ['143', '155'], 'value': '+'},{'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '+'},{'id': '144', 'type': 'string', 'children': [], 'value': '"<p style=\'text-align:center\'>("'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'binary_operator', 'children': ['149', '154'], 'value': '-'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'nrows'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'integer', 'children': [], 'value': '20'},{'id': '155', 'type': 'string', 'children': [], 'value': '" more rows)</p>\\n"'},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'out'}
def _repr_html_(self): out = "<table class='taqltable' style='overflow-x:auto'>\n" if not(all([colname[:4] == "Col_" for colname in self.colnames()])): out += "<tr>" for colname in self.colnames(): out += "<th><b>"+colname+"</b></th>" out += "</tr>" cropped = False rowcount = 0 for row in self: rowout = _format_row(row, self.colnames(), self) rowcount += 1 out += rowout if "\n" in rowout: out += "\n" out += "\n" if rowcount >= 20: cropped = True break if out[-2:] == "\n\n": out = out[:-1] out += "</table>" if cropped: out += ("<p style='text-align:center'>(" + str(self.nrows()-20)+" more rows)</p>\n") return out
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'handle_import'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'compilation'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '8', 'type': 'block', 'children': ['9', '16', '27', '52', '58', '62', '111', '127']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'PurePosixPath'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'search_exts'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'compilation'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'compiler'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'dynamic_extensions'},{'id': '27', 'type': 'if_statement', 'children': ['28', '37', '44']},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '32'], 'value': 'and'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '36'], 'value': 'in'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'search_exts'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'stem'},{'id': '44', 'type': 'else_clause', 'children': ['45']},{'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': 'basename'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'relative_to'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'search_path'},{'id': '61', 'type': 'list', 'children': [], 'value': '[]'},{'id': '62', 'type': 'if_statement', 'children': ['63', '68', '83']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'relative_to'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'is_absolute'},{'id': '67', 'type': 'argument_list', 'children': []},{'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': 'relative_to'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'PurePosixPath'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'list_splat', 'children': ['76']},{'id': '76', 'type': 'subscript', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'relative_to'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '80', 'type': 'slice', 'children': ['81', '82']},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'colon', 'children': []},{'id': '83', 'type': 'elif_clause', 'children': ['84', '89']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'source_file'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'search_path'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'tuple', 'children': ['97', '102']},{'id': '97', 'type': 'attribute', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'source_file'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '102', 'type': 'binary_operator', 'children': ['103', '110'], 'value': '/'},{'id': '103', 'type': 'attribute', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'source_file'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'relpath'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'relative_to'},{'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': 'search_path'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '116', 'type': 'generator_expression', 'children': ['117', '120']},{'id': '117', 'type': 'tuple', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'relative_to'},{'id': '120', 'type': 'for_in_clause', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '122', 'type': 'attribute', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'compilation'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'compiler'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'search_path'},{'id': '127', 'type': 'for_statement', 'children': ['128', '131', '138']},{'id': '128', 'type': 'pattern_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '133', 'type': 'argument_list', 'children': ['134', '137']},{'id': '134', 'type': 'tuple', 'children': ['135', '136']},{'id': '135', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '136', 'type': 'string', 'children': [], 'value': "''"},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'search_exts'},{'id': '138', 'type': 'block', 'children': ['139', '147']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '142', 'type': 'binary_operator', 'children': ['143', '146'], 'value': '+'},{'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '+'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '147', 'type': 'for_statement', 'children': ['148', '151', '152']},{'id': '148', 'type': 'pattern_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'relative_to'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'search_path'},{'id': '152', 'type': 'block', 'children': ['153', '159', '176', '188', '194', '203']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'relpath'},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '/'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'relative_to'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'relpath'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'PurePosixPath'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '171']},{'id': '166', 'type': 'attribute', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'normpath'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'relpath'},{'id': '176', 'type': 'if_statement', 'children': ['177', '186']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '183'], 'value': '=='},{'id': '178', 'type': 'attribute', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'source_file'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '183', 'type': 'tuple', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'relpath'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'continue_statement', 'children': []},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '/'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'relpath'},{'id': '194', 'type': 'if_statement', 'children': ['195', '201']},{'id': '195', 'type': 'not_operator', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '200', 'type': 'argument_list', 'children': []},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'continue_statement', 'children': []},{'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': 'SourceFile'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'relpath'}
def handle_import(self, name, compilation, rule): path = PurePosixPath(name) search_exts = list(compilation.compiler.dynamic_extensions) if path.suffix and path.suffix in search_exts: basename = path.stem else: basename = path.name relative_to = path.parent search_path = [] if relative_to.is_absolute(): relative_to = PurePosixPath(*relative_to.parts[1:]) elif rule.source_file.origin: search_path.append(( rule.source_file.origin, rule.source_file.relpath.parent / relative_to, )) search_path.extend( (origin, relative_to) for origin in compilation.compiler.search_path ) for prefix, suffix in product(('_', ''), search_exts): filename = prefix + basename + suffix for origin, relative_to in search_path: relpath = relative_to / filename relpath = PurePosixPath(os.path.normpath(str(relpath))) if rule.source_file.key == (origin, relpath): continue path = origin / relpath if not path.exists(): continue return SourceFile.read(origin, relpath)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_properties'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '8', 'type': 'block', 'children': ['9', '31', '44', '67', '76', '87', '95', '104', '109', '118']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '14']},{'id': '11', 'type': 'pattern_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'raw_value'},{'id': '14', 'type': 'subscript', 'children': ['15', '28']},{'id': '15', 'type': '()', 'children': ['16']},{'id': '16', 'type': 'binary_operator', 'children': ['17', '26'], 'value': '+'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_prop_split_re'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '21', 'type': 'argument_list', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '25', 'type': 'integer', 'children': [], 'value': '1'},{'id': '26', 'type': 'list', 'children': ['27'], 'value': '[None]'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'slice', 'children': ['29', '30']},{'id': '29', 'type': 'colon', 'children': []},{'id': '30', 'type': 'integer', 'children': [], 'value': '2'},{'id': '31', 'type': 'if_statement', 'children': ['32', '35']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'raw_value'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'raw_value'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'raw_value'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'try_statement', 'children': ['45', '60']},{'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': 'is_var'},{'id': '49', 'type': '()', 'children': ['50']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '59'], 'value': '=='},{'id': '51', 'type': 'subscript', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'prop'},{'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': 'prop'},{'id': '59', 'type': 'string', 'children': [], 'value': "'='"},{'id': '60', 'type': 'except_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'is_var'},{'id': '66', 'type': 'False', 'children': []},{'id': '67', 'type': 'if_statement', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'is_var'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'warn_deprecated'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '75', 'type': 'string', 'children': [], 'value': '"Assignment with = is deprecated; use : instead."'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'calculator'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_make_calculator'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'calculator'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'do_glob_math'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '104', 'type': 'if_statement', 'children': ['105', '107']},{'id': '105', 'type': 'not_operator', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'return_statement', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '112', 'type': 'binary_operator', 'children': ['113', '117'], 'value': '+'},{'id': '113', 'type': '()', 'children': ['114']},{'id': '114', 'type': 'boolean_operator', 'children': ['115', '116'], 'value': 'or'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'scope'},{'id': '116', 'type': 'string', 'children': [], 'value': "''"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '118', 'type': 'if_statement', 'children': ['119', '131', '306']},{'id': '119', 'type': 'boolean_operator', 'children': ['120', '121'], 'value': 'or'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'is_var'},{'id': '121', 'type': 'boolean_operator', 'children': ['122', '128'], 'value': 'and'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'string', 'children': [], 'value': "'$'"},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'is'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'raw_value'},{'id': '130', 'type': 'None', 'children': []},{'id': '131', 'type': 'block', 'children': ['132', '136', '140', '208', '215', '235', '246']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'is_default'},{'id': '135', 'type': 'False', 'children': []},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'is_global'},{'id': '139', 'type': 'True', 'children': []},{'id': '140', 'type': 'while_statement', 'children': ['141', '142']},{'id': '141', 'type': 'True', 'children': []},{'id': '142', 'type': 'block', 'children': ['143', '153', '172', '178']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'raw_value'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'None', 'children': []},{'id': '152', 'type': 'integer', 'children': [], 'value': '1'},{'id': '153', 'type': 'if_statement', 'children': ['154', '170']},{'id': '154', 'type': 'boolean_operator', 'children': ['155', '161'], 'value': 'or'},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '160'], 'value': '<'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '160', 'type': 'integer', 'children': [], 'value': '2'},{'id': '161', 'type': 'not_operator', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'string', 'children': [], 'value': "'!'"},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'break_statement', 'children': []},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '177']},{'id': '174', 'type': 'pattern_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'raw_value'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '178', 'type': 'if_statement', 'children': ['179', '182', '187', '196']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '=='},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '181', 'type': 'string', 'children': [], 'value': "'!default'"},{'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': 'is_default'},{'id': '186', 'type': 'True', 'children': []},{'id': '187', 'type': 'elif_clause', 'children': ['188', '191']},{'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': '=='},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '190', 'type': 'string', 'children': [], 'value': "'!global'"},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'is_global'},{'id': '195', 'type': 'True', 'children': []},{'id': '196', 'type': 'else_clause', 'children': ['197']},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'raise_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': '"Unrecognized flag: {0}"'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'normalize_var'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '215', 'type': 'try_statement', 'children': ['216', '228']},{'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': 'existing_value'},{'id': '220', 'type': 'call', 'children': ['221', '226']},{'id': '221', 'type': 'attribute', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'variable'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '228', 'type': 'except_clause', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'existing_value'},{'id': '234', 'type': 'None', 'children': []},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'is_defined'},{'id': '238', 'type': 'boolean_operator', 'children': ['239', '242'], 'value': 'and'},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': 'is'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'existing_value'},{'id': '241', 'type': 'None', 'children': []},{'id': '242', 'type': 'not_operator', 'children': ['243']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'existing_value'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'is_null'},{'id': '246', 'type': 'if_statement', 'children': ['247', '250', '252']},{'id': '247', 'type': 'boolean_operator', 'children': ['248', '249'], 'value': 'and'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'is_default'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'is_defined'},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'pass_statement', 'children': []},{'id': '252', 'type': 'else_clause', 'children': ['253']},{'id': '253', 'type': 'block', 'children': ['254', '280', '292']},{'id': '254', 'type': 'if_statement', 'children': ['255', '271']},{'id': '255', 'type': 'boolean_operator', 'children': ['256', '264'], 'value': 'and'},{'id': '256', 'type': 'boolean_operator', 'children': ['257', '258'], 'value': 'and'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'is_defined'},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'string', 'children': [], 'value': "'$'"},{'id': '264', 'type': 'call', 'children': ['265', '270']},{'id': '265', 'type': 'attribute', 'children': ['266', '269']},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '268', 'type': 'integer', 'children': [], 'value': '1'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'isupper'},{'id': '270', 'type': 'argument_list', 'children': []},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '277', 'type': 'argument_list', 'children': ['278', '279']},{'id': '278', 'type': 'string', 'children': [], 'value': '"Constant %r redefined"'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'assignment', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'calculator'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'calculate'},{'id': '287', 'type': 'argument_list', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'raw_value'},{'id': '289', 'type': 'keyword_argument', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'divide'},{'id': '291', 'type': 'True', 'children': []},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '299']},{'id': '294', 'type': 'attribute', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'set_variable'},{'id': '299', 'type': 'argument_list', 'children': ['300', '301', '302']},{'id': '300', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'local_only'},{'id': '304', 'type': 'not_operator', 'children': ['305']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'is_global'},{'id': '306', 'type': 'else_clause', 'children': ['307']},{'id': '307', 'type': 'block', 'children': ['308', '317', '337', '394']},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'assignment', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '311', 'type': 'call', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'calculator'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'apply_vars'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '317', 'type': 'if_statement', 'children': ['318', '321', '326']},{'id': '318', 'type': 'comparison_operator', 'children': ['319', '320'], 'value': 'is'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'raw_value'},{'id': '320', 'type': 'None', 'children': []},{'id': '321', 'type': 'block', 'children': ['322']},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'assignment', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '325', 'type': 'None', 'children': []},{'id': '326', 'type': 'else_clause', 'children': ['327']},{'id': '327', 'type': 'block', 'children': ['328']},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '331', 'type': 'call', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'calculator'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'calculate'},{'id': '335', 'type': 'argument_list', 'children': ['336']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'raw_value'},{'id': '337', 'type': 'if_statement', 'children': ['338', '341', '343', '353']},{'id': '338', 'type': 'comparison_operator', 'children': ['339', '340'], 'value': 'is'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '340', 'type': 'None', 'children': []},{'id': '341', 'type': 'block', 'children': ['342']},{'id': '342', 'type': 'pass_statement', 'children': []},{'id': '343', 'type': 'elif_clause', 'children': ['344', '351']},{'id': '344', 'type': 'call', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '346', 'type': 'argument_list', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '351', 'type': 'block', 'children': ['352']},{'id': '352', 'type': 'pass_statement', 'children': []},{'id': '353', 'type': 'else_clause', 'children': ['354']},{'id': '354', 'type': 'block', 'children': ['355', '361', '377', '383']},{'id': '355', 'type': 'if_statement', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'is_null'},{'id': '359', 'type': 'block', 'children': ['360']},{'id': '360', 'type': 'return_statement', 'children': []},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'assignment', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '364', 'type': 'call', 'children': ['365', '370']},{'id': '365', 'type': 'attribute', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'legacy_compiler_options'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '370', 'type': 'argument_list', 'children': ['371', '372']},{'id': '371', 'type': 'string', 'children': [], 'value': "'style'"},{'id': '372', 'type': 'attribute', 'children': ['373', '376']},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'compiler'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'output_style'},{'id': '377', 'type': 'expression_statement', 'children': ['378']},{'id': '378', 'type': 'assignment', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'compress'},{'id': '380', 'type': 'comparison_operator', 'children': ['381', '382'], 'value': '=='},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'style'},{'id': '382', 'type': 'string', 'children': [], 'value': "'compressed'"},{'id': '383', 'type': 'expression_statement', 'children': ['384']},{'id': '384', 'type': 'assignment', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '386', 'type': 'call', 'children': ['387', '390']},{'id': '387', 'type': 'attribute', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'render'},{'id': '390', 'type': 'argument_list', 'children': ['391']},{'id': '391', 'type': 'keyword_argument', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'compress'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'compress'},{'id': '394', 'type': 'expression_statement', 'children': ['395']},{'id': '395', 'type': 'call', 'children': ['396', '401']},{'id': '396', 'type': 'attribute', 'children': ['397', '400']},{'id': '397', 'type': 'attribute', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '401', 'type': 'argument_list', 'children': ['402']},{'id': '402', 'type': 'tuple', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': '_prop'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'value'}
def _get_properties(self, rule, scope, block): prop, raw_value = (_prop_split_re.split(block.prop, 1) + [None])[:2] if raw_value is not None: raw_value = raw_value.strip() try: is_var = (block.prop[len(prop)] == '=') except IndexError: is_var = False if is_var: warn_deprecated(rule, "Assignment with = is deprecated; use : instead.") calculator = self._make_calculator(rule.namespace) prop = prop.strip() prop = calculator.do_glob_math(prop) if not prop: return _prop = (scope or '') + prop if is_var or prop.startswith('$') and raw_value is not None: is_default = False is_global = True while True: splits = raw_value.rsplit(None, 1) if len(splits) < 2 or not splits[1].startswith('!'): break raw_value, flag = splits if flag == '!default': is_default = True elif flag == '!global': is_global = True else: raise ValueError("Unrecognized flag: {0}".format(flag)) _prop = normalize_var(_prop) try: existing_value = rule.namespace.variable(_prop) except KeyError: existing_value = None is_defined = existing_value is not None and not existing_value.is_null if is_default and is_defined: pass else: if is_defined and prop.startswith('$') and prop[1].isupper(): log.warn("Constant %r redefined", prop) value = calculator.calculate(raw_value, divide=True) rule.namespace.set_variable( _prop, value, local_only=not is_global) else: _prop = calculator.apply_vars(_prop) if raw_value is None: value = None else: value = calculator.calculate(raw_value) if value is None: pass elif isinstance(value, six.string_types): pass else: if value.is_null: return style = rule.legacy_compiler_options.get( 'style', self.compiler.output_style) compress = style == 'compressed' value = value.render(compress=compress) rule.properties.append((_prop, value))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'longest_common_subsequence'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'mergefunc'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '30', '34', '63', '67', '152', '161', '170', '174', '238', '244']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'mergefunc'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'function_definition', 'children': ['16', '17', '20']},{'id': '16', 'type': 'function_name', 'children': [], 'value': 'mergefunc'},{'id': '17', 'type': 'parameters', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '20', 'type': 'block', 'children': ['21', '28']},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': '=='},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'eq'},{'id': '33', 'type': 'dictionary', 'children': []},{'id': '34', 'type': 'for_statement', 'children': ['35', '38', '42']},{'id': '35', 'type': 'pattern_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'aval'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'for_statement', 'children': ['44', '47', '51']},{'id': '44', 'type': 'pattern_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'bval'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '58']},{'id': '54', 'type': 'subscript', 'children': ['55', '56', '57']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'eq'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mergefunc'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'aval'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'bval'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'prefix_lcs_length'},{'id': '66', 'type': 'dictionary', 'children': []},{'id': '67', 'type': 'for_statement', 'children': ['68', '69', '78']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '71', 'type': 'argument_list', 'children': ['72', '74']},{'id': '72', 'type': 'unary_operator', 'children': ['73'], 'value': '-'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'for_statement', 'children': ['80', '81', '90']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '83', 'type': 'argument_list', 'children': ['84', '86']},{'id': '84', 'type': 'unary_operator', 'children': ['85'], 'value': '-'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '90', 'type': 'block', 'children': ['91', '145']},{'id': '91', 'type': 'if_statement', 'children': ['92', '101', '106', '125']},{'id': '92', 'type': 'boolean_operator', 'children': ['93', '97'], 'value': 'or'},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '=='},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '95', 'type': 'unary_operator', 'children': ['96'], 'value': '-'},{'id': '96', 'type': 'integer', 'children': [], 'value': '1'},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': '=='},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '99', 'type': 'unary_operator', 'children': ['100'], 'value': '-'},{'id': '100', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'l'},{'id': '105', 'type': 'integer', 'children': [], 'value': '0'},{'id': '106', 'type': 'elif_clause', 'children': ['107', '111']},{'id': '107', 'type': 'subscript', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'eq'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '115', 'type': 'binary_operator', 'children': ['116', '124'], 'value': '+'},{'id': '116', 'type': 'subscript', 'children': ['117', '118', '121']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'prefix_lcs_length'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '-'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '-'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '123', 'type': 'integer', 'children': [], 'value': '1'},{'id': '124', 'type': 'integer', 'children': [], 'value': '1'},{'id': '125', 'type': 'else_clause', 'children': ['126']},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '132', 'type': 'argument_list', 'children': ['133', '139']},{'id': '133', 'type': 'subscript', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'prefix_lcs_length'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '-'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'id': '139', 'type': 'subscript', 'children': ['140', '141', '144']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'prefix_lcs_length'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '-'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '151']},{'id': '147', 'type': 'subscript', 'children': ['148', '149', '150']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'prefix_lcs_length'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '160'], 'value': '-'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '164', 'type': 'binary_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': 'b'},{'id': '169', 'type': 'integer', 'children': [], 'value': '1'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '173', 'type': 'list', 'children': [], 'value': '[]'},{'id': '174', 'type': 'while_statement', 'children': ['175', '182']},{'id': '175', 'type': 'boolean_operator', 'children': ['176', '179'], 'value': 'and'},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': '>='},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '>='},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '181', 'type': 'integer', 'children': [], 'value': '0'},{'id': '182', 'type': 'block', 'children': ['183', '190']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'merged'},{'id': '186', 'type': 'subscript', 'children': ['187', '188', '189']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'eq'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '190', 'type': 'if_statement', 'children': ['191', '194', '213', '232']},{'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': 'is'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'merged'},{'id': '193', 'type': 'None', 'children': []},{'id': '194', 'type': 'block', 'children': ['195', '205', '209']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'tuple', 'children': ['202', '203', '204']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'merged'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'augmented_assignment', 'children': ['207', '208'], 'value': '-='},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '208', 'type': 'integer', 'children': [], 'value': '1'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'augmented_assignment', 'children': ['211', '212'], 'value': '-='},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '212', 'type': 'integer', 'children': [], 'value': '1'},{'id': '213', 'type': 'elif_clause', 'children': ['214', '227']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '221'], 'value': '>'},{'id': '215', 'type': 'subscript', 'children': ['216', '217', '218']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'prefix_lcs_length'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '-'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '220', 'type': 'integer', 'children': [], 'value': '1'},{'id': '221', 'type': 'subscript', 'children': ['222', '223', '226']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'prefix_lcs_length'},{'id': '223', 'type': 'binary_operator', 'children': ['224', '225'], 'value': '-'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '225', 'type': 'integer', 'children': [], 'value': '1'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'augmented_assignment', 'children': ['230', '231'], 'value': '-='},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'bi'},{'id': '231', 'type': 'integer', 'children': [], 'value': '1'},{'id': '232', 'type': 'else_clause', 'children': ['233']},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'augmented_assignment', 'children': ['236', '237'], 'value': '-='},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'ai'},{'id': '237', 'type': 'integer', 'children': [], 'value': '1'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '243', 'type': 'argument_list', 'children': []},{'id': '244', 'type': 'return_statement', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'ret'}
def longest_common_subsequence(a, b, mergefunc=None): if mergefunc is None: def mergefunc(a, b): if a == b: return a return None eq = {} for ai, aval in enumerate(a): for bi, bval in enumerate(b): eq[ai, bi] = mergefunc(aval, bval) prefix_lcs_length = {} for ai in range(-1, len(a)): for bi in range(-1, len(b)): if ai == -1 or bi == -1: l = 0 elif eq[ai, bi]: l = prefix_lcs_length[ai - 1, bi - 1] + 1 else: l = max( prefix_lcs_length[ai, bi - 1], prefix_lcs_length[ai - 1, bi]) prefix_lcs_length[ai, bi] = l ai = len(a) - 1 bi = len(b) - 1 ret = [] while ai >= 0 and bi >= 0: merged = eq[ai, bi] if merged is not None: ret.append((ai, bi, merged)) ai -= 1 bi -= 1 elif prefix_lcs_length[ai, bi - 1] > prefix_lcs_length[ai - 1, bi]: bi -= 1 else: ai -= 1 ret.reverse() return ret
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'determine_encoding'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '5', 'type': 'block', 'children': ['6', '10', '16', '84', '105', '147', '217', '226', '235', '324']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '9', 'type': 'string', 'children': [], 'value': "'UTF-8'"},{'id': '10', 'type': 'if_statement', 'children': ['11', '13']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '16', 'type': 'if_statement', 'children': ['17', '24']},{'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': 'buf'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'id': '24', 'type': 'block', 'children': ['25', '40', '44', '48']},{'id': '25', 'type': 'if_statement', 'children': ['26', '31']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '30'], 'value': '=='},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'string', 'children': [], 'value': "'\\ufeff'"},{'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': 'buf'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '37', 'type': 'slice', 'children': ['38', '39']},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'colon', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'charset_start'},{'id': '43', 'type': 'string', 'children': [], 'value': '\'@charset "\''},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'charset_end'},{'id': '47', 'type': 'string', 'children': [], 'value': '\'";\''},{'id': '48', 'type': 'if_statement', 'children': ['49', '55', '80']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'charset_start'},{'id': '55', 'type': 'block', 'children': ['56', '63', '73']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'charset_start'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'charset_end'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '76', 'type': 'slice', 'children': ['77', '78', '79']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '78', 'type': 'colon', 'children': []},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '80', 'type': 'else_clause', 'children': ['81']},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'return_statement', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '84', 'type': 'if_statement', 'children': ['85', '92']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '91'], 'value': '=='},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '88', 'type': 'slice', 'children': ['89', '90']},{'id': '89', 'type': 'colon', 'children': []},{'id': '90', 'type': 'integer', 'children': [], 'value': '3'},{'id': '91', 'type': 'string', 'children': [], 'value': "b'\\xef\\xbb\\xbf'"},{'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': 'bom_encoding'},{'id': '96', 'type': 'string', 'children': [], 'value': "'UTF-8'"},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '102', 'type': 'slice', 'children': ['103', '104']},{'id': '103', 'type': 'integer', 'children': [], 'value': '3'},{'id': '104', 'type': 'colon', 'children': []},{'id': '105', 'type': 'if_statement', 'children': ['106', '113', '126']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '112'], 'value': '=='},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '109', 'type': 'slice', 'children': ['110', '111']},{'id': '110', 'type': 'colon', 'children': []},{'id': '111', 'type': 'integer', 'children': [], 'value': '4'},{'id': '112', 'type': 'string', 'children': [], 'value': "b'\\x00\\x00\\xfe\\xff'"},{'id': '113', 'type': 'block', 'children': ['114', '118']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '117', 'type': 'string', 'children': [], 'value': "'UTF-32BE'"},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '123', 'type': 'slice', 'children': ['124', '125']},{'id': '124', 'type': 'integer', 'children': [], 'value': '4'},{'id': '125', 'type': 'colon', 'children': []},{'id': '126', 'type': 'elif_clause', 'children': ['127', '134']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '133'], 'value': '=='},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '130', 'type': 'slice', 'children': ['131', '132']},{'id': '131', 'type': 'colon', 'children': []},{'id': '132', 'type': 'integer', 'children': [], 'value': '4'},{'id': '133', 'type': 'string', 'children': [], 'value': "b'\\xff\\xfe\\x00\\x00'"},{'id': '134', 'type': 'block', 'children': ['135', '139']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '138', 'type': 'string', 'children': [], 'value': "'UTF-32LE'"},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '144', 'type': 'slice', 'children': ['145', '146']},{'id': '145', 'type': 'integer', 'children': [], 'value': '4'},{'id': '146', 'type': 'colon', 'children': []},{'id': '147', 'type': 'if_statement', 'children': ['148', '155', '161', '175', '196']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '154'], 'value': '=='},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '151', 'type': 'slice', 'children': ['152', '153']},{'id': '152', 'type': 'colon', 'children': []},{'id': '153', 'type': 'integer', 'children': [], 'value': '4'},{'id': '154', 'type': 'string', 'children': [], 'value': "b'\\x00\\x00\\xff\\xfe'"},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'raise_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'UnicodeError'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'string', 'children': [], 'value': '"UTF-32-2143 is not supported"'},{'id': '161', 'type': 'elif_clause', 'children': ['162', '169']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '168'], 'value': '=='},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '165', 'type': 'slice', 'children': ['166', '167']},{'id': '166', 'type': 'colon', 'children': []},{'id': '167', 'type': 'integer', 'children': [], 'value': '4'},{'id': '168', 'type': 'string', 'children': [], 'value': "b'\\xfe\\xff\\x00\\x00'"},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'raise_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'UnicodeError'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'string', 'children': [], 'value': '"UTF-32-2143 is not supported"'},{'id': '175', 'type': 'elif_clause', 'children': ['176', '183']},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '182'], 'value': '=='},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '179', 'type': 'slice', 'children': ['180', '181']},{'id': '180', 'type': 'colon', 'children': []},{'id': '181', 'type': 'integer', 'children': [], 'value': '2'},{'id': '182', 'type': 'string', 'children': [], 'value': "b'\\xfe\\xff'"},{'id': '183', 'type': 'block', 'children': ['184', '188']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '187', 'type': 'string', 'children': [], 'value': "'UTF-16BE'"},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '193', 'type': 'slice', 'children': ['194', '195']},{'id': '194', 'type': 'integer', 'children': [], 'value': '2'},{'id': '195', 'type': 'colon', 'children': []},{'id': '196', 'type': 'elif_clause', 'children': ['197', '204']},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '203'], 'value': '=='},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '200', 'type': 'slice', 'children': ['201', '202']},{'id': '201', 'type': 'colon', 'children': []},{'id': '202', 'type': 'integer', 'children': [], 'value': '2'},{'id': '203', 'type': 'string', 'children': [], 'value': "b'\\xff\\xfe'"},{'id': '204', 'type': 'block', 'children': ['205', '209']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '208', 'type': 'string', 'children': [], 'value': "'UTF-16LE'"},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '214', 'type': 'slice', 'children': ['215', '216']},{'id': '215', 'type': 'integer', 'children': [], 'value': '2'},{'id': '216', 'type': 'colon', 'children': []},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'charset_start'},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'string', 'children': [], 'value': '\'@charset "\''},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'charset_end'},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'string', 'children': [], 'value': '\'";\''},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '235', 'type': 'if_statement', 'children': ['236', '242', '318']},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'charset_start'},{'id': '242', 'type': 'block', 'children': ['243', '250', '260', '269', '278', '291']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'charset_start'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '257', 'type': 'argument_list', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'charset_end'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'encoded_encoding'},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '265', 'type': 'slice', 'children': ['266', '267', '268']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '267', 'type': 'colon', 'children': []},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'encoded_encoding'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'encoded_charset'},{'id': '281', 'type': 'subscript', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '283', 'type': 'slice', 'children': ['284', '285']},{'id': '284', 'type': 'colon', 'children': []},{'id': '285', 'type': 'binary_operator', 'children': ['286', '287'], 'value': '+'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'end'},{'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': 'charset_end'},{'id': '291', 'type': 'if_statement', 'children': ['292', '306']},{'id': '292', 'type': '()', 'children': ['293']},{'id': '293', 'type': 'comparison_operator', 'children': ['294', '300'], 'value': '!='},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'encoded_charset'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'encoded_charset'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '306', 'type': 'block', 'children': ['307']},{'id': '307', 'type': 'raise_statement', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'UnicodeError'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'call', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'string', 'children': [], 'value': '"@charset {0} is incompatible with detected encoding {1}"'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '315', 'type': 'argument_list', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '318', 'type': 'else_clause', 'children': ['319']},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'assignment', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'bom_encoding'},{'id': '324', 'type': 'return_statement', 'children': ['325']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'encoding'}
def determine_encoding(buf): bom_encoding = 'UTF-8' if not buf: return bom_encoding if isinstance(buf, six.text_type): if buf[0] == '\ufeff': buf = buf[0:] charset_start = '@charset "' charset_end = '";' if buf.startswith(charset_start): start = len(charset_start) end = buf.index(charset_end, start) return buf[start:end] else: return bom_encoding if buf[:3] == b'\xef\xbb\xbf': bom_encoding = 'UTF-8' buf = buf[3:] if buf[:4] == b'\x00\x00\xfe\xff': bom_encoding = 'UTF-32BE' buf = buf[4:] elif buf[:4] == b'\xff\xfe\x00\x00': bom_encoding = 'UTF-32LE' buf = buf[4:] if buf[:4] == b'\x00\x00\xff\xfe': raise UnicodeError("UTF-32-2143 is not supported") elif buf[:4] == b'\xfe\xff\x00\x00': raise UnicodeError("UTF-32-2143 is not supported") elif buf[:2] == b'\xfe\xff': bom_encoding = 'UTF-16BE' buf = buf[2:] elif buf[:2] == b'\xff\xfe': bom_encoding = 'UTF-16LE' buf = buf[2:] charset_start = '@charset "'.encode(bom_encoding) charset_end = '";'.encode(bom_encoding) if buf.startswith(charset_start): start = len(charset_start) end = buf.index(charset_end, start) encoded_encoding = buf[start:end] encoding = encoded_encoding.decode(bom_encoding) encoded_charset = buf[:end + len(charset_end)] if (encoded_charset.decode(encoding) != encoded_charset.decode(bom_encoding)): raise UnicodeError( "@charset {0} is incompatible with detected encoding {1}" .format(bom_encoding, encoding)) else: encoding = bom_encoding return encoding
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_draw_surfaces'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'surface'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'surfaces'},{'id': '8', 'type': 'block', 'children': ['9', '15', '21', '31', '39', '47', '58', '64', '70', '93', '102', '109']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'surface_blit'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'surface'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'blit'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '20']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ox'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'oy'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '26']},{'id': '23', 'type': 'pattern_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_tile_view'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'topleft'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'hit'},{'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': '_layer_quadtree'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'get_tile'},{'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': 'data'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_tile_image'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'tile_layers'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'visible_tile_layers'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'dirty'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dirty_append'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'dirty'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '70', 'type': 'function_definition', 'children': ['71', '72', '74']},{'id': '71', 'type': 'function_name', 'children': [], 'value': 'sprite_sort'},{'id': '72', 'type': 'parameters', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'expression_list', 'children': ['77', '80']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '79', 'type': 'integer', 'children': [], 'value': '2'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '86'], 'value': '+'},{'id': '81', 'type': 'subscript', 'children': ['82', '85']},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'get_height'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'surfaces'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sprite_sort'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'layer_getter'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'integer', 'children': [], 'value': '2'},{'id': '109', 'type': 'for_statement', 'children': ['110', '113', '118']},{'id': '110', 'type': 'pattern_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'surfaces'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'layer_getter'},{'id': '118', 'type': 'block', 'children': ['119', '124', '169']},{'id': '119', 'type': 'delete_statement', 'children': ['120']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'dirty'},{'id': '122', 'type': 'slice', 'children': ['123']},{'id': '123', 'type': 'colon', 'children': []},{'id': '124', 'type': 'for_statement', 'children': ['125', '126', '127']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'try_statement', 'children': ['129', '136', '152']},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '135', 'type': 'integer', 'children': [], 'value': '3'},{'id': '136', 'type': 'except_clause', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'dirty_append'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'surface_blit'},{'id': '145', 'type': 'argument_list', 'children': ['146', '149']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'else_clause', 'children': ['153']},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'dirty_append'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'surface_blit'},{'id': '160', 'type': 'argument_list', 'children': ['161', '164', '167', '168']},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '163', 'type': 'integer', 'children': [], 'value': '0'},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'None', 'children': []},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '172']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'dirty_rect'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'dirty'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'for_statement', 'children': ['174', '175', '185']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'dirty_rect'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'move'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'ox'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'oy'},{'id': '185', 'type': 'block', 'children': ['186', '194']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '193']},{'id': '188', 'type': 'pattern_list', 'children': ['189', '190', '191', '192']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'tw'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'th'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '194', 'type': 'for_statement', 'children': ['195', '196', '207']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '196', 'type': 'list_comprehension', 'children': ['197', '198', '201']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '198', 'type': 'for_in_clause', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'tile_layers'},{'id': '201', 'type': 'if_clause', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '207', 'type': 'block', 'children': ['208', '235', '252']},{'id': '208', 'type': 'if_statement', 'children': ['209', '218']},{'id': '209', 'type': 'boolean_operator', 'children': ['210', '213'], 'value': 'and'},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'tall_sprites'},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': '=='},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '+'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '217', 'type': 'integer', 'children': [], 'value': '1'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'if_statement', 'children': ['220', '233']},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '226'], 'value': '<='},{'id': '221', 'type': 'binary_operator', 'children': ['222', '225'], 'value': '+'},{'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '-'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'oy'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'th'},{'id': '226', 'type': 'binary_operator', 'children': ['227', '230'], 'value': '-'},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'dirty_rect'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'bottom'},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'tall_sprites'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'continue_statement', 'children': []},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'tile'},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'get_tile'},{'id': '240', 'type': 'argument_list', 'children': ['241', '246', '251']},{'id': '241', 'type': 'binary_operator', 'children': ['242', '245'], 'value': '+'},{'id': '242', 'type': 'binary_operator', 'children': ['243', '244'], 'value': '//'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'tw'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '246', 'type': 'binary_operator', 'children': ['247', '250'], 'value': '+'},{'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '//'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'th'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'boolean_operator', 'children': ['254', '255'], 'value': 'and'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'tile'},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'surface_blit'},{'id': '257', 'type': 'argument_list', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'tile'},{'id': '259', 'type': 'tuple', 'children': ['260', '263']},{'id': '260', 'type': 'binary_operator', 'children': ['261', '262'], 'value': '-'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'ox'},{'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '-'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'oy'}
def _draw_surfaces(self, surface, offset, surfaces): surface_blit = surface.blit ox, oy = offset left, top = self._tile_view.topleft hit = self._layer_quadtree.hit get_tile = self.data.get_tile_image tile_layers = tuple(self.data.visible_tile_layers) dirty = list() dirty_append = dirty.append def sprite_sort(i): return i[2], i[1][1] + i[0].get_height() surfaces.sort(key=sprite_sort) layer_getter = itemgetter(2) for layer, group in groupby(surfaces, layer_getter): del dirty[:] for i in group: try: flags = i[3] except IndexError: dirty_append(surface_blit(i[0], i[1])) else: dirty_append(surface_blit(i[0], i[1], None, flags)) for dirty_rect in dirty: for r in hit(dirty_rect.move(ox, oy)): x, y, tw, th = r for l in [i for i in tile_layers if gt(i, layer)]: if self.tall_sprites and l == layer + 1: if y - oy + th <= dirty_rect.bottom - self.tall_sprites: continue tile = get_tile(x // tw + left, y // th + top, l) tile and surface_blit(tile, (x - ox, y - oy))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_tile_images_by_rect'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '6', 'type': 'block', 'children': ['7', '36', '47', '55', '63', '69', '75', '81', '90']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '13']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'rev'},{'id': '9', 'type': 'parameters', 'children': ['10', '11', '12']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '13', 'type': 'block', 'children': ['14', '23']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': '<'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'start'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '26', 'type': 'argument_list', 'children': ['27', '35']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '29', 'type': 'slice', 'children': ['30', '31', '32']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '31', 'type': 'colon', 'children': []},{'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '+'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '43']},{'id': '38', 'type': 'pattern_list', 'children': ['39', '40', '41', '42']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'x1'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'y1'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x2'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'y2'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'rect_to_bb'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'images'},{'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': 'tmx'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'tmx'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'at'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_animated_tile'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'tracked_gids'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_tracked_gids'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'anim_map'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_animation_map'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_animation_queue'},{'id': '90', 'type': 'for_statement', 'children': ['91', '92', '97']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'l'},{'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': 'tmx'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'visible_tile_layers'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'for_statement', 'children': ['99', '102', '112']},{'id': '99', 'type': 'pattern_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'rev'},{'id': '104', 'type': 'argument_list', 'children': ['105', '110', '111']},{'id': '105', 'type': 'attribute', 'children': ['106', '109']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'layers'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'y1'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'y2'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'for_statement', 'children': ['114', '117', '131']},{'id': '114', 'type': 'pattern_list', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'gid'},{'id': '117', 'type': 'list_comprehension', 'children': ['118', '119', '127']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '119', 'type': 'for_in_clause', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'rev'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125', '126']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'x1'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'x2'},{'id': '127', 'type': 'if_clause', 'children': ['128']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'block', 'children': ['132', '153']},{'id': '132', 'type': 'if_statement', 'children': ['133', '138']},{'id': '133', 'type': 'boolean_operator', 'children': ['134', '135'], 'value': 'and'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'in'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'gid'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'tracked_gids'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '148']},{'id': '141', 'type': 'attribute', 'children': ['142', '147']},{'id': '142', 'type': 'attribute', 'children': ['143', '146']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'anim_map'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'gid'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'positions'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'tuple', 'children': ['150', '151', '152']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '153', 'type': 'try_statement', 'children': ['154', '167']},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'yield', 'children': ['157']},{'id': '157', 'type': 'expression_list', 'children': ['158', '159', '160', '161']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'at'},{'id': '163', 'type': 'tuple', 'children': ['164', '165', '166']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '167', 'type': 'except_clause', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'yield', 'children': ['172']},{'id': '172', 'type': 'expression_list', 'children': ['173', '174', '175', '176']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'gid'}
def get_tile_images_by_rect(self, rect): def rev(seq, start, stop): if start < 0: start = 0 return enumerate(seq[start:stop + 1], start) x1, y1, x2, y2 = rect_to_bb(rect) images = self.tmx.images layers = self.tmx.layers at = self._animated_tile tracked_gids = self._tracked_gids anim_map = self._animation_map track = bool(self._animation_queue) for l in self.tmx.visible_tile_layers: for y, row in rev(layers[l].data, y1, y2): for x, gid in [i for i in rev(row, x1, x2) if i[1]]: if track and gid in tracked_gids: anim_map[gid].positions.add((x, y, l)) try: yield x, y, l, at[(x, y, l)] except KeyError: yield x, y, l, images[gid]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'describe_pdb'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'pdb_id'},{'id': '5', 'type': 'block', 'children': ['6', '16', '23', '34']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'get_info'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'pdb_id'},{'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'url_root'},{'id': '15', 'type': 'string', 'children': [], 'value': "'http://www.rcsb.org/pdb/rest/describePDB?structureId='"},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'to_dict'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'remove_at_sign'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'subscript', 'children': ['30', '33']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '32', 'type': 'string', 'children': [], 'value': "'PDBdescription'"},{'id': '33', 'type': 'string', 'children': [], 'value': "'PDB'"},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'out'}
def describe_pdb(pdb_id): out = get_info(pdb_id, url_root = 'http://www.rcsb.org/pdb/rest/describePDB?structureId=') out = to_dict(out) out = remove_at_sign(out['PDBdescription']['PDB']) return out
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'download_file_from_google_drive'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'file_id'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dest_path'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'unzip'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'showsize'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '23', '35']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'destination_directory'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'dest_path'},{'id': '23', 'type': 'if_statement', 'children': ['24', '29']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'destination_directory'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'destination_directory'},{'id': '35', 'type': 'if_statement', 'children': ['36', '43']},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '42'], 'value': 'or'},{'id': '37', 'type': 'not_operator', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'dest_path'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '43', 'type': 'block', 'children': ['44', '52', '66', '72', '92', '101', '131', '138', '143', '153', '158']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'Session'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '55', 'type': 'argument_list', 'children': ['56', '63']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'Downloading {} into {}... '"},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'file_id'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'dest_path'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '65', 'type': 'string', 'children': [], 'value': "''"},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '79', 'type': 'argument_list', 'children': ['80', '83', '89']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'GoogleDriveDownloader'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'DOWNLOAD_URL'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '85', 'type': 'dictionary', 'children': ['86']},{'id': '86', 'type': 'pair', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'file_id'},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '91', 'type': 'True', 'children': []},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'GoogleDriveDownloader'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_get_confirm_token'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '101', 'type': 'if_statement', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '103', 'type': 'block', 'children': ['104', '114']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '107', 'type': 'dictionary', 'children': ['108', '111']},{'id': '108', 'type': 'pair', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'file_id'},{'id': '111', 'type': 'pair', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': "'confirm'"},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '121', 'type': 'argument_list', 'children': ['122', '125', '128']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'GoogleDriveDownloader'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'DOWNLOAD_URL'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '130', 'type': 'True', 'children': []},{'id': '131', 'type': 'if_statement', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'showsize'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'current_download_size'},{'id': '141', 'type': 'list', 'children': ['142'], 'value': '[0]'},{'id': '142', 'type': 'integer', 'children': [], 'value': '0'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'GoogleDriveDownloader'},{'id': '147', 'type': 'identifier', 'children': [], 'value': '_save_response_content'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150', '151', '152']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'dest_path'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'showsize'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'current_download_size'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'string', 'children': [], 'value': "'Done.'"},{'id': '158', 'type': 'if_statement', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'unzip'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'try_statement', 'children': ['162', '203']},{'id': '162', 'type': 'block', 'children': ['163', '171', '177', '198']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168']},{'id': '167', 'type': 'string', 'children': [], 'value': "'Unzipping...'"},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '170', 'type': 'string', 'children': [], 'value': "''"},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'with_statement', 'children': ['178', '190']},{'id': '178', 'type': 'with_clause', 'children': ['179']},{'id': '179', 'type': 'with_item', 'children': ['180']},{'id': '180', 'type': 'as_pattern', 'children': ['181', '188']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'zipfile'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'ZipFile'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'dest_path'},{'id': '187', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '188', 'type': 'as_pattern_target', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'z'},{'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': 'z'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'extractall'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'destination_directory'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'string', 'children': [], 'value': "'Done.'"},{'id': '203', 'type': 'except_clause', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'zipfile'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'BadZipfile'},{'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': 'warnings'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'string', 'children': [], 'value': '\'Ignoring `unzip` since "{}" does not look like a valid zip file\''},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'file_id'}
def download_file_from_google_drive(file_id, dest_path, overwrite=False, unzip=False, showsize=False): destination_directory = dirname(dest_path) if not exists(destination_directory): makedirs(destination_directory) if not exists(dest_path) or overwrite: session = requests.Session() print('Downloading {} into {}... '.format(file_id, dest_path), end='') stdout.flush() response = session.get(GoogleDriveDownloader.DOWNLOAD_URL, params={'id': file_id}, stream=True) token = GoogleDriveDownloader._get_confirm_token(response) if token: params = {'id': file_id, 'confirm': token} response = session.get(GoogleDriveDownloader.DOWNLOAD_URL, params=params, stream=True) if showsize: print() current_download_size = [0] GoogleDriveDownloader._save_response_content(response, dest_path, showsize, current_download_size) print('Done.') if unzip: try: print('Unzipping...', end='') stdout.flush() with zipfile.ZipFile(dest_path, 'r') as z: z.extractall(destination_directory) print('Done.') except zipfile.BadZipfile: warnings.warn('Ignoring `unzip` since "{}" does not look like a valid zip file'.format(file_id))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'server_extensions_handshake'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'requested'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'supported'},{'id': '6', 'type': 'block', 'children': ['7', '11', '86', '178']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'accepts'},{'id': '10', 'type': 'dictionary', 'children': []},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'offer'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'requested'},{'id': '14', 'type': 'block', 'children': ['15', '31']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '18', 'type': 'call', 'children': ['19', '30']},{'id': '19', 'type': 'attribute', 'children': ['20', '29']},{'id': '20', 'type': 'subscript', 'children': ['21', '28']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'offer'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': '";"'},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'for_statement', 'children': ['32', '33', '34']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'supported'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'if_statement', 'children': ['36', '41']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': '=='},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '41', 'type': 'block', 'children': ['42', '51']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'accept'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'accept'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'offer'},{'id': '51', 'type': 'if_statement', 'children': ['52', '55', '64']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'accept'},{'id': '54', 'type': 'True', 'children': []},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '63']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'accepts'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '63', 'type': 'True', 'children': []},{'id': '64', 'type': 'elif_clause', 'children': ['65', '72']},{'id': '65', 'type': 'boolean_operator', 'children': ['66', '69'], 'value': 'and'},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'is'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'accept'},{'id': '68', 'type': 'False', 'children': []},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'accept'},{'id': '71', 'type': 'None', 'children': []},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '80']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'accepts'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'accept'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'string', 'children': [], 'value': '"ascii"'},{'id': '86', 'type': 'if_statement', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'accepts'},{'id': '88', 'type': 'block', 'children': ['89', '93', '171']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'extensions'},{'id': '92', 'type': 'list', 'children': [], 'value': '[]'},{'id': '93', 'type': 'for_statement', 'children': ['94', '97', '102']},{'id': '94', 'type': 'pattern_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'accepts'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'if_statement', 'children': ['104', '107', '120']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'is'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '106', 'type': 'True', 'children': []},{'id': '107', 'type': 'block', 'children': ['108']},{'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': 'extensions'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': '"ascii"'},{'id': '120', 'type': 'else_clause', 'children': ['121']},{'id': '121', 'type': 'block', 'children': ['122', '131']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'string', 'children': [], 'value': '"ascii"'},{'id': '131', 'type': 'if_statement', 'children': ['132', '135', '152']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': '=='},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '134', 'type': 'string', 'children': [], 'value': '""'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'extensions'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '150']},{'id': '143', 'type': 'attribute', 'children': ['144', '149']},{'id': '144', 'type': '()', 'children': ['145']},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '%'},{'id': '146', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '147', 'type': '()', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'string', 'children': [], 'value': '"ascii"'},{'id': '152', 'type': 'else_clause', 'children': ['153']},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'extensions'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '169']},{'id': '161', 'type': 'attribute', 'children': ['162', '168']},{'id': '162', 'type': '()', 'children': ['163']},{'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '%'},{'id': '164', 'type': 'string', 'children': [], 'value': '"%s; %s"'},{'id': '165', 'type': 'tuple', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'string', 'children': [], 'value': '"ascii"'},{'id': '171', 'type': 'return_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'string', 'children': [], 'value': 'b", "'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'extensions'},{'id': '178', 'type': 'return_statement', 'children': ['179']},{'id': '179', 'type': 'None', 'children': []}
def server_extensions_handshake(requested, supported): accepts = {} for offer in requested: name = offer.split(";", 1)[0].strip() for extension in supported: if extension.name == name: accept = extension.accept(offer) if accept is True: accepts[extension.name] = True elif accept is not False and accept is not None: accepts[extension.name] = accept.encode("ascii") if accepts: extensions = [] for name, params in accepts.items(): if params is True: extensions.append(name.encode("ascii")) else: params = params.decode("ascii") if params == "": extensions.append(("%s" % (name)).encode("ascii")) else: extensions.append(("%s; %s" % (name, params)).encode("ascii")) return b", ".join(extensions) return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'listfiles'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data_name'},{'id': '5', 'type': 'block', 'children': ['6', '16', '38', '43', '47', '189']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'data_source'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'get_data_object'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'data_name'},{'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'use_data_config'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'if_statement', 'children': ['17', '19']},{'id': '17', 'type': 'not_operator', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'data_source'},{'id': '19', 'type': 'block', 'children': ['20', '32']},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'in'},{'id': '22', 'type': 'string', 'children': [], 'value': "'output'"},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data_name'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'floyd_logger'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': '"Note: You cannot clone the output of a running job. You need to wait for it to finish."'},{'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': 'sys'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '41', 'type': 'list', 'children': ['42'], 'value': "['']"},{'id': '42', 'type': 'string', 'children': [], 'value': "''"},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '46', 'type': 'list', 'children': [], 'value': '[]'},{'id': '47', 'type': 'while_statement', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '49', 'type': 'block', 'children': ['50', '58', '70', '86', '107', '113', '127']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'cur_dir'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': '"/resources/{}/{}?content=true"'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '65', 'type': 'argument_list', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'data_source'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'resource_id'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'cur_dir'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '73', 'type': 'call', 'children': ['74', '85']},{'id': '74', 'type': 'attribute', 'children': ['75', '84']},{'id': '75', 'type': 'call', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'DataClient'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': '"GET"'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'if_statement', 'children': ['87', '92']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '91'], 'value': '>'},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '90', 'type': 'string', 'children': [], 'value': "'skipped_files'"},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'block', 'children': ['93']},{'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': 'floyd_logger'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100', '101', '104']},{'id': '99', 'type': 'string', 'children': [], 'value': '"Warning: in directory \'%s\', %s/%s files skipped (too many files)"'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'cur_dir'},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '103', 'type': 'string', 'children': [], 'value': "'skipped_files'"},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '106', 'type': 'string', 'children': [], 'value': "'total_files'"},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '112', 'type': 'string', 'children': [], 'value': "'files'"},{'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': 'files'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '121', 'type': 'lambda', 'children': ['122', '124']},{'id': '122', 'type': 'lambda_parameters', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '126', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '127', 'type': 'for_statement', 'children': ['128', '129', '130']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '130', 'type': 'block', 'children': ['131', '145', '158', '165']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'cur_dir'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '144', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '145', 'type': 'if_statement', 'children': ['146', '151']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': '=='},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '149', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '150', 'type': 'string', 'children': [], 'value': "'directory'"},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'augmented_assignment', 'children': ['154', '155'], 'value': '+='},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'sep'},{'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': 'paths'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '165', 'type': 'if_statement', 'children': ['166', '171']},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '170'], 'value': '=='},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '169', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '170', 'type': 'string', 'children': [], 'value': "'directory'"},{'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': 'dirs'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '184']},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'cur_dir'},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '188', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '189', 'type': 'for_statement', 'children': ['190', '191', '192']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'floyd_logger'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'path'}
def listfiles(data_name): data_source = get_data_object(data_name, use_data_config=False) if not data_source: if 'output' in data_name: floyd_logger.info("Note: You cannot clone the output of a running job. You need to wait for it to finish.") sys.exit() dirs = [''] paths = [] while dirs: cur_dir = dirs.pop() url = "/resources/{}/{}?content=true".format(data_source.resource_id, cur_dir) response = DataClient().request("GET", url).json() if response['skipped_files'] > 0: floyd_logger.info("Warning: in directory '%s', %s/%s files skipped (too many files)", cur_dir, response['skipped_files'], response['total_files']) files = response['files'] files.sort(key=lambda f: f['name']) for f in files: path = os.path.join(cur_dir, f['name']) if f['type'] == 'directory': path += os.sep paths.append(path) if f['type'] == 'directory': dirs.append(os.path.join(cur_dir, f['name'])) for path in paths: floyd_logger.info(path)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'download'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'relative'},{'id': '9', 'type': 'False', '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': 'timeout'},{'id': '15', 'type': 'integer', 'children': [], 'value': '5'},{'id': '16', 'type': 'block', 'children': ['17', '28', '40', '44', '57', '67']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'request_url'},{'id': '20', 'type': 'conditional_expression', 'children': ['21', '26', '27'], 'value': 'if'},{'id': '21', 'type': 'binary_operator', 'children': ['22', '25'], 'value': '+'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'relative'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'floyd_logger'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': '"Downloading file from url: {}"'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'request_url'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'request_headers'},{'id': '43', 'type': 'dictionary', 'children': []},{'id': '44', 'type': 'if_statement', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'auth_header'},{'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': 'request_headers'},{'id': '53', 'type': 'string', 'children': [], 'value': '"Authorization"'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'auth_header'},{'id': '57', 'type': 'if_statement', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '59', 'type': 'block', 'children': ['60']},{'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': 'request_headers'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '67', 'type': 'try_statement', 'children': ['68', '197']},{'id': '68', 'type': 'block', 'children': ['69', '87', '94', '195']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '81', '84']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'request_url'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'request_headers'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '86', 'type': 'True', 'children': []},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'check_response_status'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '94', 'type': 'with_statement', 'children': ['95', '105']},{'id': '95', 'type': 'with_clause', 'children': ['96']},{'id': '96', 'type': 'with_item', 'children': ['97']},{'id': '97', 'type': 'as_pattern', 'children': ['98', '103']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '102', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '103', 'type': 'as_pattern_target', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '105', 'type': 'block', 'children': ['106', '117', '132']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'content_length'},{'id': '109', 'type': 'call', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'string', 'children': [], 'value': "'x-floydhub-content-length'"},{'id': '117', 'type': 'if_statement', 'children': ['118', '120']},{'id': '118', 'type': 'not_operator', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'content_length'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'content_length'},{'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': 'response'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'string', 'children': [], 'value': "'content-length'"},{'id': '132', 'type': 'if_statement', 'children': ['133', '134', '172']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'content_length'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'for_statement', 'children': ['136', '137', '161']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'progress'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'bar'},{'id': '141', 'type': 'argument_list', 'children': ['142', '150']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'iter_content'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'expected_size'},{'id': '152', 'type': 'binary_operator', 'children': ['153', '160'], 'value': '+'},{'id': '153', 'type': '()', 'children': ['154']},{'id': '154', 'type': 'binary_operator', 'children': ['155', '159'], 'value': '/'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'content_length'},{'id': '159', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'if_statement', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '172', 'type': 'else_clause', 'children': ['173']},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'for_statement', 'children': ['175', '176', '184']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'iter_content'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '183', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'if_statement', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'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': 'f'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '195', 'type': 'return_statement', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '197', 'type': 'except_clause', 'children': ['198', '206']},{'id': '198', 'type': 'as_pattern', 'children': ['199', '204']},{'id': '199', 'type': 'attribute', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'},{'id': '204', 'type': 'as_pattern_target', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '206', 'type': 'block', 'children': ['207', '219']},{'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': 'floyd_logger'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'string', 'children': [], 'value': '"Exception: {}"'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'string', 'children': [], 'value': '"Cannot connect to the Floyd server. Check your internet connection."'}
def download(self, url, filename, relative=False, headers=None, timeout=5): request_url = self.base_url + url if relative else url floyd_logger.debug("Downloading file from url: {}".format(request_url)) request_headers = {} if self.auth_header: request_headers["Authorization"] = self.auth_header if headers: request_headers.update(headers) try: response = requests.get(request_url, headers=request_headers, timeout=timeout, stream=True) self.check_response_status(response) with open(filename, 'wb') as f: content_length = response.headers.get('x-floydhub-content-length') if not content_length: content_length = response.headers.get('content-length') if content_length: for chunk in progress.bar(response.iter_content(chunk_size=1024), expected_size=(int(content_length) / 1024) + 1): if chunk: f.write(chunk) else: for chunk in response.iter_content(chunk_size=1024): if chunk: f.write(chunk) return filename except requests.exceptions.ConnectionError as exception: floyd_logger.debug("Exception: {}".format(exception)) sys.exit("Cannot connect to the Floyd server. Check your internet connection.")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_command_line'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'open_notebook'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'command_str'},{'id': '11', 'type': 'block', 'children': ['12', '18', '32', '46', '58', '106', '150']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'floyd_command'},{'id': '15', 'type': 'list', 'children': ['16', '17'], 'value': '["floyd", "run"]'},{'id': '16', 'type': 'string', 'children': [], 'value': '"floyd"'},{'id': '17', 'type': 'string', 'children': [], 'value': '"run"'},{'id': '18', 'type': 'if_statement', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '20', 'type': 'block', 'children': ['21']},{'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': 'floyd_command'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '+'},{'id': '28', 'type': 'string', 'children': [], 'value': "'--'"},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'INSTANCE_NAME_MAP'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '32', 'type': 'if_statement', 'children': ['33', '39']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '35'], 'value': 'and'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '35', 'type': 'not_operator', 'children': ['36']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '=='},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_ENV'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'augmented_assignment', 'children': ['42', '43'], 'value': '+='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'floyd_command'},{'id': '43', 'type': 'list', 'children': ['44', '45'], 'value': '["--env", env]'},{'id': '44', 'type': 'string', 'children': [], 'value': '"--env"'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '46', 'type': 'if_statement', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'augmented_assignment', 'children': ['51', '52'], 'value': '+='},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'floyd_command'},{'id': '52', 'type': 'list', 'children': ['53', '54'], 'value': '["--message", shell_quote(message)]'},{'id': '53', 'type': 'string', 'children': [], 'value': '"--message"'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'shell_quote'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '58', 'type': 'if_statement', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'data_item'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '64', 'type': 'block', 'children': ['65', '74', '100']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'data_item'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': "':'"},{'id': '74', 'type': 'if_statement', 'children': ['75', '81']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '80'], 'value': '>'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '80', 'type': 'integer', 'children': [], 'value': '1'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'data_item'},{'id': '85', 'type': 'binary_operator', 'children': ['86', '97'], 'value': '+'},{'id': '86', 'type': 'binary_operator', 'children': ['87', '96'], 'value': '+'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'normalize_data_name'},{'id': '89', 'type': 'argument_list', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'use_data_config'},{'id': '95', 'type': 'False', 'children': []},{'id': '96', 'type': 'string', 'children': [], 'value': "':'"},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'augmented_assignment', 'children': ['102', '103'], 'value': '+='},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'floyd_command'},{'id': '103', 'type': 'list', 'children': ['104', '105'], 'value': '["--data", data_item]'},{'id': '104', 'type': 'string', 'children': [], 'value': '"--data"'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'data_item'},{'id': '106', 'type': 'if_statement', 'children': ['107', '112', '135']},{'id': '107', 'type': 'boolean_operator', 'children': ['108', '109'], 'value': 'and'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '!='},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '111', 'type': 'string', 'children': [], 'value': '"job"'},{'id': '112', 'type': 'block', 'children': ['113', '119']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'augmented_assignment', 'children': ['115', '116'], 'value': '+='},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'floyd_command'},{'id': '116', 'type': 'list', 'children': ['117', '118'], 'value': '["--mode", mode]'},{'id': '117', 'type': 'string', 'children': [], 'value': '"--mode"'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '119', 'type': 'if_statement', 'children': ['120', '123']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '=='},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '122', 'type': 'string', 'children': [], 'value': "'jupyter'"},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'if_statement', 'children': ['125', '127']},{'id': '125', 'type': 'not_operator', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'open_notebook'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'floyd_command'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'string', 'children': [], 'value': '"--no-open"'},{'id': '135', 'type': 'else_clause', 'children': ['136']},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'if_statement', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'command_str'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'floyd_command'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'shell_quote'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'command_str'},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': "' '"},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'floyd_command'}
def get_command_line(instance_type, env, message, data, mode, open_notebook, command_str): floyd_command = ["floyd", "run"] if instance_type: floyd_command.append('--' + INSTANCE_NAME_MAP[instance_type]) if env and not env == DEFAULT_ENV: floyd_command += ["--env", env] if message: floyd_command += ["--message", shell_quote(message)] if data: for data_item in data: parts = data_item.split(':') if len(parts) > 1: data_item = normalize_data_name(parts[0], use_data_config=False) + ':' + parts[1] floyd_command += ["--data", data_item] if mode and mode != "job": floyd_command += ["--mode", mode] if mode == 'jupyter': if not open_notebook: floyd_command.append("--no-open") else: if command_str: floyd_command.append(shell_quote(command_str)) return ' '.join(floyd_command)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'restart'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'job_name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'open_notebook'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'gpu'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'gpup'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'cpup'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '15', 'type': 'block', 'children': ['16', '43', '49', '53', '59', '85', '107', '126', '158', '168', '179', '188', '197', '211', '219', '233', '251']},{'id': '16', 'type': 'if_statement', 'children': ['17', '23']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '22'], 'value': '>'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '22', 'type': 'integer', 'children': [], 'value': '1'},{'id': '23', 'type': 'block', 'children': ['24', '36']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'floyd_logger'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': '"You passed more than one environment: {}. Please specify a single environment."'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'integer', 'children': [], 'value': '1'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '52', 'type': 'dictionary', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'expt_client'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ExperimentClient'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'try_statement', 'children': ['60', '73']},{'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': 'job'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'expt_client'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'normalize_job_name'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'job_name'},{'id': '73', 'type': 'except_clause', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'FloydException'},{'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': 'job'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'expt_client'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'job_name'},{'id': '85', 'type': 'if_statement', 'children': ['86', '87', '92', '99']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'gpu'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'G1_INSTANCE_TYPE'},{'id': '92', 'type': 'elif_clause', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'cpu'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'C1_INSTANCE_TYPE'},{'id': '99', 'type': 'else_clause', 'children': ['100']},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '107', 'type': 'if_statement', 'children': ['108', '111', '118']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'is'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '110', 'type': 'None', 'children': []},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '117']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '116', 'type': 'string', 'children': [], 'value': "'instance_type'"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '118', 'type': 'else_clause', 'children': ['119']},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'block', 'children': ['131', '137', '152']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'arch'},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'INSTANCE_ARCH_MAP'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '137', 'type': 'if_statement', 'children': ['138', '144']},{'id': '138', 'type': 'not_operator', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'validate_env'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'arch'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '157']},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '156', 'type': 'string', 'children': [], 'value': "'env'"},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '164']},{'id': '160', 'type': 'pattern_list', 'children': ['161', '162', '163']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'data_ids'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'show_data_info'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'process_data_ids'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '168', 'type': 'if_statement', 'children': ['169', '171']},{'id': '169', 'type': 'not_operator', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'success'},{'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': 'sys'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'id': '179', 'type': 'if_statement', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'data_ids'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '187']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '186', 'type': 'string', 'children': [], 'value': "'data_ids'"},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'data_ids'},{'id': '188', 'type': 'if_statement', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '196']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '195', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '197', 'type': 'if_statement', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '204', 'type': 'string', 'children': [], 'value': "'command'"},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'string', 'children': [], 'value': "' '"},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'command'},{'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': 'floyd_logger'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218']},{'id': '217', 'type': 'string', 'children': [], 'value': "'Restarting job %s...'"},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'job_name'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'new_job_info'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'expt_client'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'restart'},{'id': '226', 'type': 'argument_list', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '233', 'type': 'if_statement', 'children': ['234', '236']},{'id': '234', 'type': 'not_operator', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'new_job_info'},{'id': '236', 'type': 'block', 'children': ['237', '244']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'floyd_logger'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'string', 'children': [], 'value': '"Failed to restart job"'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'integer', 'children': [], 'value': '1'},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'show_new_job_info'},{'id': '254', 'type': 'argument_list', 'children': ['255', '256', '259', '260', '263', '264']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'expt_client'},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'new_job_info'},{'id': '258', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'new_job_info'},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'open_notebook'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'show_data_info'}
def restart(ctx, job_name, data, open_notebook, env, message, gpu, cpu, gpup, cpup, command): if len(env) > 1: floyd_logger.error( "You passed more than one environment: {}. Please specify a single environment.".format(env) ) sys.exit(1) env = env[0] parameters = {} expt_client = ExperimentClient() try: job = expt_client.get(normalize_job_name(job_name)) except FloydException: job = expt_client.get(job_name) if gpu: instance_type = G1_INSTANCE_TYPE elif cpu: instance_type = C1_INSTANCE_TYPE else: instance_type = job.instance_type if instance_type is not None: parameters['instance_type'] = instance_type else: instance_type = job.instance_type if env is not None: arch = INSTANCE_ARCH_MAP[instance_type] if not validate_env(env, arch): sys.exit(1) parameters['env'] = env success, data_ids, show_data_info = process_data_ids(data) if not success: sys.exit(1) if data_ids: parameters['data_ids'] = data_ids if message: parameters['description'] = message if command: parameters['command'] = ' '.join(command) floyd_logger.info('Restarting job %s...', job_name) new_job_info = expt_client.restart(job.id, parameters=parameters) if not new_job_info: floyd_logger.error("Failed to restart job") sys.exit(1) show_new_job_info(expt_client, new_job_info['name'], new_job_info, job.mode, open_notebook, show_data_info)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_user'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'using'},{'id': '7', 'type': 'string', 'children': [], 'value': "'records'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'part_of_week'},{'id': '13', 'type': 'string', 'children': [], 'value': "'allweek'"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'part_of_day'},{'id': '16', 'type': 'string', 'children': [], 'value': "'allday'"},{'id': '17', 'type': 'block', 'children': ['18', '79', '148', '201', '250']},{'id': '18', 'type': 'if_statement', 'children': ['19', '22', '29']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '=='},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'using'},{'id': '21', 'type': 'string', 'children': [], 'value': "'recharges'"},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'recharges'},{'id': '29', 'type': 'else_clause', 'children': ['30']},{'id': '30', 'type': 'block', 'children': ['31', '37']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '37', 'type': 'if_statement', 'children': ['38', '41', '59']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '40', 'type': 'string', 'children': [], 'value': "'callandtext'"},{'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': 'records'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '47', 'type': 'argument_list', 'children': ['48', '58']},{'id': '48', 'type': 'lambda', 'children': ['49', '51']},{'id': '49', 'type': 'lambda_parameters', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '55'], 'value': 'in'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '55', 'type': 'list', 'children': ['56', '57'], 'value': "['call', 'text']"},{'id': '56', 'type': 'string', 'children': [], 'value': "'call'"},{'id': '57', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '59', 'type': 'elif_clause', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '69', 'type': 'argument_list', 'children': ['70', '78']},{'id': '70', 'type': 'lambda', 'children': ['71', '73']},{'id': '71', 'type': 'lambda_parameters', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '77'], 'value': '=='},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '79', 'type': 'if_statement', 'children': ['80', '83', '105', '131']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': '=='},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'part_of_week'},{'id': '82', 'type': 'string', 'children': [], 'value': "'weekday'"},{'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': 'records'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '89', 'type': 'argument_list', 'children': ['90', '104']},{'id': '90', 'type': 'lambda', 'children': ['91', '93']},{'id': '91', 'type': 'lambda_parameters', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '101'], 'value': 'not'},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'isoweekday'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'weekend'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '105', 'type': 'elif_clause', 'children': ['106', '109']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '=='},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'part_of_week'},{'id': '108', 'type': 'string', 'children': [], 'value': "'weekend'"},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '115', 'type': 'argument_list', 'children': ['116', '130']},{'id': '116', 'type': 'lambda', 'children': ['117', '119']},{'id': '117', 'type': 'lambda_parameters', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '127'], 'value': 'in'},{'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': 'r'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'isoweekday'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'weekend'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '131', 'type': 'elif_clause', 'children': ['132', '135']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': '!='},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'part_of_week'},{'id': '134', 'type': 'string', 'children': [], 'value': "'allweek'"},{'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': 'KeyError'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '146']},{'id': '141', 'type': 'attribute', 'children': ['142', '145']},{'id': '142', 'type': 'concatenated_string', 'children': ['143', '144']},{'id': '143', 'type': 'string', 'children': [], 'value': '"{} is not a valid value for part_of_week. it should be \'weekday\', "'},{'id': '144', 'type': 'string', 'children': [], 'value': '"\'weekend\' or \'allweek\'."'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'part_of_week'},{'id': '148', 'type': 'if_statement', 'children': ['149', '156', '177']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '153'], 'value': '<'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'night_start'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'night_end'},{'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': 'night_filter'},{'id': '160', 'type': 'lambda', 'children': ['161', '163']},{'id': '161', 'type': 'lambda_parameters', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '167', '174'], 'value': '>'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'night_end'},{'id': '167', 'type': 'call', 'children': ['168', '173']},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '173', 'type': 'argument_list', 'children': []},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'night_start'},{'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': 'night_filter'},{'id': '182', 'type': 'lambda', 'children': ['183', '185']},{'id': '183', 'type': 'lambda_parameters', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '185', 'type': 'not_operator', 'children': ['186']},{'id': '186', 'type': '()', 'children': ['187']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '191', '198'], 'value': '<'},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'night_end'},{'id': '191', 'type': 'call', 'children': ['192', '197']},{'id': '192', 'type': 'attribute', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'night_start'},{'id': '201', 'type': 'if_statement', 'children': ['202', '205', '222', '235']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': '=='},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'part_of_day'},{'id': '204', 'type': 'string', 'children': [], 'value': "'day'"},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '211', 'type': 'argument_list', 'children': ['212', '221']},{'id': '212', 'type': 'lambda', 'children': ['213', '215']},{'id': '213', 'type': 'lambda_parameters', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '215', 'type': 'not_operator', 'children': ['216']},{'id': '216', 'type': '()', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'night_filter'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '222', 'type': 'elif_clause', 'children': ['223', '226']},{'id': '223', 'type': 'comparison_operator', 'children': ['224', '225'], 'value': '=='},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'part_of_day'},{'id': '225', 'type': 'string', 'children': [], 'value': "'night'"},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '232', 'type': 'argument_list', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'night_filter'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '235', 'type': 'elif_clause', 'children': ['236', '239']},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': '!='},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'part_of_day'},{'id': '238', 'type': 'string', 'children': [], 'value': "'allday'"},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'raise_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'string', 'children': [], 'value': '"{} is not a valid value for part_of_day. It should be \'day\', \'night\' or \'allday\'."'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'part_of_day'},{'id': '250', 'type': 'return_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'records'}
def filter_user(user, using='records', interaction=None, part_of_week='allweek', part_of_day='allday'): if using == 'recharges': records = user.recharges else: records = user.records if interaction == 'callandtext': records = filter( lambda r: r.interaction in ['call', 'text'], records) elif interaction is not None: records = filter(lambda r: r.interaction == interaction, records) if part_of_week == 'weekday': records = filter( lambda r: r.datetime.isoweekday() not in user.weekend, records) elif part_of_week == 'weekend': records = filter( lambda r: r.datetime.isoweekday() in user.weekend, records) elif part_of_week != 'allweek': raise KeyError( "{} is not a valid value for part_of_week. it should be 'weekday', " "'weekend' or 'allweek'.".format(part_of_week)) if user.night_start < user.night_end: night_filter = lambda r: user.night_end > r.datetime.time( ) > user.night_start else: night_filter = lambda r: not( user.night_end < r.datetime.time() < user.night_start) if part_of_day == 'day': records = filter(lambda r: not(night_filter(r)), records) elif part_of_day == 'night': records = filter(night_filter, records) elif part_of_day != 'allday': raise KeyError( "{} is not a valid value for part_of_day. It should be 'day', 'night' or 'allday'.".format(part_of_day)) return list(records)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'infer_type'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'block', 'children': ['6', '22', '31', '95']},{'id': '6', 'type': 'if_statement', 'children': ['7', '19']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '9', 'type': 'argument_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '11', 'type': 'tuple', 'children': ['12', '16']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'numbers'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Number'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': "'scalar'"},{'id': '22', 'type': 'if_statement', 'children': ['23', '28']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'SummaryStats'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': "'summarystats'"},{'id': '31', 'type': 'if_statement', 'children': ['32', '37']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '36', 'type': 'string', 'children': [], 'value': '"__len__"'},{'id': '37', 'type': 'block', 'children': ['38', '50', '70', '81']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '41', 'type': 'list_comprehension', 'children': ['42', '43', '46']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '46', 'type': 'if_clause', 'children': ['47']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '49', 'type': 'None', 'children': []},{'id': '50', 'type': 'if_statement', 'children': ['51', '67']},{'id': '51', 'type': 'boolean_operator', 'children': ['52', '58'], 'value': 'or'},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '57'], 'value': '=='},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '60', 'type': 'argument_list', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'numbers'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'Number'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': "'distribution_scalar'"},{'id': '70', 'type': 'if_statement', 'children': ['71', '78']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '73', 'type': 'argument_list', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '76', 'type': 'integer', 'children': [], 'value': '0'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'SummaryStats'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': "'distribution_summarystats'"},{'id': '81', 'type': 'raise_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '91']},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'concatenated_string', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': '"{} is not a valid input. It should be a number, a SummaryStats "'},{'id': '89', 'type': 'string', 'children': [], 'value': '"object, or None"'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'raise_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'concatenated_string', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': '"{} is not a valid input. It should be a number, a SummaryStats "'},{'id': '103', 'type': 'string', 'children': [], 'value': '"object, or a list"'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'data'}
def infer_type(data): if isinstance(data, (type(None), numbers.Number)): return 'scalar' if isinstance(data, SummaryStats): return 'summarystats' if hasattr(data, "__len__"): data = [x for x in data if x is not None] if len(data) == 0 or isinstance(data[0], numbers.Number): return 'distribution_scalar' if isinstance(data[0], SummaryStats): return 'distribution_summarystats' raise TypeError( "{} is not a valid input. It should be a number, a SummaryStats " "object, or None".format(data[0])) raise TypeError( "{} is not a valid input. It should be a number, a SummaryStats " "object, or a list".format(data))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'churn_rate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'summary'},{'id': '7', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '10', 'type': 'block', 'children': ['11', '29', '59', '67', '75', '91', '95', '99', '144', '154', '228']},{'id': '11', 'type': 'if_statement', 'children': ['12', '20']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '19'], 'value': '=='},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'statistics'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'summary'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'summary'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '32', 'type': 'dictionary', 'children': ['33', '36', '50', '53', '56']},{'id': '33', 'type': 'pair', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'groupby'"},{'id': '35', 'type': 'string', 'children': [], 'value': "'week'"},{'id': '36', 'type': 'pair', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'divide_by'"},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'list', 'children': ['42', '46'], 'value': "[\n ('part_of_week', ['allweek']),\n ('part_of_day', ['allday'])\n ]"},{'id': '42', 'type': 'tuple', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': "'part_of_week'"},{'id': '44', 'type': 'list', 'children': ['45'], 'value': "['allweek']"},{'id': '45', 'type': 'string', 'children': [], 'value': "'allweek'"},{'id': '46', 'type': 'tuple', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': "'part_of_day'"},{'id': '48', 'type': 'list', 'children': ['49'], 'value': "['allday']"},{'id': '49', 'type': 'string', 'children': [], 'value': "'allday'"},{'id': '50', 'type': 'pair', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': "'using'"},{'id': '52', 'type': 'string', 'children': [], 'value': "'records'"},{'id': '53', 'type': 'pair', 'children': ['54', '55']},{'id': '54', 'type': 'string', 'children': [], 'value': "'filter_empty'"},{'id': '55', 'type': 'True', 'children': []},{'id': '56', 'type': 'pair', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "'binning'"},{'id': '58', 'type': 'True', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'grouping_query'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'weekly_positions'},{'id': '70', 'type': 'subscript', 'children': ['71', '74']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '73', 'type': 'integer', 'children': [], 'value': '0'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'all_positions'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '83', 'type': 'generator_expression', 'children': ['84', '85', '88']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '85', 'type': 'for_in_clause', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'weekly_positions'},{'id': '88', 'type': 'for_in_clause', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'frequencies'},{'id': '94', 'type': 'dictionary', 'children': []},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'cos_dist'},{'id': '98', 'type': 'list', 'children': [], 'value': '[]'},{'id': '99', 'type': 'for_statement', 'children': ['100', '103', '107']},{'id': '100', 'type': 'pattern_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'week'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'week_positions'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'weekly_positions'},{'id': '107', 'type': 'block', 'children': ['108', '115', '126']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'week_positions'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'sum'},{'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': 'count'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'frequencies'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'week'},{'id': '131', 'type': 'list_comprehension', 'children': ['132', '141']},{'id': '132', 'type': 'binary_operator', 'children': ['133', '140'], 'value': '/'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '139', 'type': 'integer', 'children': [], 'value': '0'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '141', 'type': 'for_in_clause', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'all_positions'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'all_indexes'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'all_positions'},{'id': '154', 'type': 'for_statement', 'children': ['155', '158', '169']},{'id': '155', 'type': 'pattern_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'f_1'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'f_2'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'pairwise'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'frequencies'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '168', 'type': 'argument_list', 'children': []},{'id': '169', 'type': 'block', 'children': ['170', '186', '198', '210']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '175', 'type': 'generator_expression', 'children': ['176', '183']},{'id': '176', 'type': 'binary_operator', 'children': ['177', '180'], 'value': '*'},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'f_1'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'f_2'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '183', 'type': 'for_in_clause', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'all_indexes'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'denom_1'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '191', 'type': 'generator_expression', 'children': ['192', '195']},{'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '**'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '194', 'type': 'integer', 'children': [], 'value': '2'},{'id': '195', 'type': 'for_in_clause', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'f_1'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'denom_2'},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '203', 'type': 'generator_expression', 'children': ['204', '207']},{'id': '204', 'type': 'binary_operator', 'children': ['205', '206'], 'value': '**'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '206', 'type': 'integer', 'children': [], 'value': '2'},{'id': '207', 'type': 'for_in_clause', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'f_2'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'cos_dist'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'binary_operator', 'children': ['217', '218'], 'value': '-'},{'id': '217', 'type': 'integer', 'children': [], 'value': '1'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '/'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '220', 'type': '()', 'children': ['221']},{'id': '221', 'type': 'binary_operator', 'children': ['222', '225'], 'value': '*'},{'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '**'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'denom_1'},{'id': '224', 'type': 'float', 'children': [], 'value': '.5'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '227'], 'value': '**'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'denom_2'},{'id': '227', 'type': 'float', 'children': [], 'value': '.5'},{'id': '228', 'type': 'return_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'statistics'},{'id': '231', 'type': 'argument_list', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'cos_dist'},{'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'summary'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'summary'}
def churn_rate(user, summary='default', **kwargs): if len(user.records) == 0: return statistics([], summary=summary) query = { 'groupby': 'week', 'divide_by': OrderedDict([ ('part_of_week', ['allweek']), ('part_of_day', ['allday']) ]), 'using': 'records', 'filter_empty': True, 'binning': True } rv = grouping_query(user, query) weekly_positions = rv[0][1] all_positions = list(set(p for l in weekly_positions for p in l)) frequencies = {} cos_dist = [] for week, week_positions in enumerate(weekly_positions): count = Counter(week_positions) total = sum(count.values()) frequencies[week] = [count.get(p, 0) / total for p in all_positions] all_indexes = range(len(all_positions)) for f_1, f_2 in pairwise(list(frequencies.values())): num = sum(f_1[a] * f_2[a] for a in all_indexes) denom_1 = sum(f ** 2 for f in f_1) denom_2 = sum(f ** 2 for f in f_2) cos_dist.append(1 - num / (denom_1 ** .5 * denom_2 ** .5)) return statistics(cos_dist, summary=summary)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'describe'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '40', '54', '68', '111', '128', '138', '161', '191', '226', '256', '277', '298', '319']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '11']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'format_int'},{'id': '8', 'type': 'parameters', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'if_statement', 'children': ['13', '20', '32']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '17'], 'value': 'or'},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '=='},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '16', 'type': 'integer', 'children': [], 'value': '0'},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '=='},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '19', 'type': 'integer', 'children': [], 'value': '1'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '%'},{'id': '23', 'type': 'string', 'children': [], 'value': '"%i %s"'},{'id': '24', 'type': 'tuple', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '28', 'type': 'slice', 'children': ['29', '30']},{'id': '29', 'type': 'colon', 'children': []},{'id': '30', 'type': 'unary_operator', 'children': ['31'], 'value': '-'},{'id': '31', 'type': 'integer', 'children': [], 'value': '1'},{'id': '32', 'type': 'else_clause', 'children': ['33']},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '%'},{'id': '36', 'type': 'string', 'children': [], 'value': '"%i %s"'},{'id': '37', 'type': 'tuple', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'empty_box'},{'id': '43', 'type': 'binary_operator', 'children': ['44', '53'], 'value': '+'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '50'], 'value': '+'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '49'], 'value': '+'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'Colors'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'OKGREEN'},{'id': '49', 'type': 'string', 'children': [], 'value': "'[ ]'"},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'Colors'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ENDC'},{'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': 'filled_box'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '67'], 'value': '+'},{'id': '58', 'type': 'binary_operator', 'children': ['59', '64'], 'value': '+'},{'id': '59', 'type': 'binary_operator', 'children': ['60', '63'], 'value': '+'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'Colors'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'OKGREEN'},{'id': '63', 'type': 'string', 'children': [], 'value': "'[x]'"},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'Colors'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ENDC'},{'id': '67', 'type': 'string', 'children': [], 'value': "' '"},{'id': '68', 'type': 'if_statement', 'children': ['69', '74', '82']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': 'is'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '73', 'type': 'None', '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': 'print'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '+'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'empty_box'},{'id': '81', 'type': 'string', 'children': [], 'value': '"No records stored"'},{'id': '82', 'type': 'else_clause', 'children': ['83']},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': '()', 'children': ['89']},{'id': '89', 'type': 'binary_operator', 'children': ['90', '102'], 'value': '+'},{'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '+'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'filled_box'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'format_int'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': '"records"'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '%'},{'id': '103', 'type': 'string', 'children': [], 'value': '" from %s to %s"'},{'id': '104', 'type': 'tuple', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'nb_contacts'},{'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': 'bc'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'number_of_contacts'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122', '125']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '124', 'type': 'string', 'children': [], 'value': "'callandtext'"},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '127', 'type': 'None', 'children': []},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'nb_contacts'},{'id': '131', 'type': 'subscript', 'children': ['132', '137']},{'id': '132', 'type': 'subscript', 'children': ['133', '136']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'nb_contacts'},{'id': '135', 'type': 'string', 'children': [], 'value': "'allweek'"},{'id': '136', 'type': 'string', 'children': [], 'value': "'allday'"},{'id': '137', 'type': 'string', 'children': [], 'value': "'callandtext'"},{'id': '138', 'type': 'if_statement', 'children': ['139', '140', '152']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'nb_contacts'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '+'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'filled_box'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'format_int'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': '"contacts"'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'nb_contacts'},{'id': '152', 'type': 'else_clause', 'children': ['153']},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '+'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'empty_box'},{'id': '160', 'type': 'string', 'children': [], 'value': '"No contacts"'},{'id': '161', 'type': 'if_statement', 'children': ['162', '165', '182']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'has_attributes'},{'id': '165', 'type': 'block', 'children': ['166']},{'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': 'binary_operator', 'children': ['171', '172'], 'value': '+'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'filled_box'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'format_int'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176']},{'id': '175', 'type': 'string', 'children': [], 'value': '"attributes"'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '182', 'type': 'else_clause', 'children': ['183']},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '+'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'empty_box'},{'id': '190', 'type': 'string', 'children': [], 'value': '"No attribute stored"'},{'id': '191', 'type': 'if_statement', 'children': ['192', '200', '208']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '199'], 'value': '=='},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'antennas'},{'id': '199', 'type': 'integer', 'children': [], 'value': '0'},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '+'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'empty_box'},{'id': '207', 'type': 'string', 'children': [], 'value': '"No antenna stored"'},{'id': '208', 'type': 'else_clause', 'children': ['209']},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '+'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'filled_box'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'format_int'},{'id': '218', 'type': 'argument_list', 'children': ['219', '220']},{'id': '219', 'type': 'string', 'children': [], 'value': '"antennas"'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'antennas'},{'id': '226', 'type': 'if_statement', 'children': ['227', '230', '247']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'has_recharges'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'binary_operator', 'children': ['236', '237'], 'value': '+'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'filled_box'},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'format_int'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241']},{'id': '240', 'type': 'string', 'children': [], 'value': '"recharges"'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'recharges'},{'id': '247', 'type': 'else_clause', 'children': ['248']},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '+'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'empty_box'},{'id': '255', 'type': 'string', 'children': [], 'value': '"No recharges"'},{'id': '256', 'type': 'if_statement', 'children': ['257', '260', '268']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'has_home'},{'id': '260', 'type': 'block', 'children': ['261']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'binary_operator', 'children': ['266', '267'], 'value': '+'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'filled_box'},{'id': '267', 'type': 'string', 'children': [], 'value': '"Has home"'},{'id': '268', 'type': 'else_clause', 'children': ['269']},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'binary_operator', 'children': ['275', '276'], 'value': '+'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'empty_box'},{'id': '276', 'type': 'string', 'children': [], 'value': '"No home"'},{'id': '277', 'type': 'if_statement', 'children': ['278', '281', '289']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'has_text'},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'binary_operator', 'children': ['287', '288'], 'value': '+'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'filled_box'},{'id': '288', 'type': 'string', 'children': [], 'value': '"Has texts"'},{'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', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'binary_operator', 'children': ['296', '297'], 'value': '+'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'empty_box'},{'id': '297', 'type': 'string', 'children': [], 'value': '"No texts"'},{'id': '298', 'type': 'if_statement', 'children': ['299', '302', '310']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'has_call'},{'id': '302', 'type': 'block', 'children': ['303']},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'binary_operator', 'children': ['308', '309'], 'value': '+'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'filled_box'},{'id': '309', 'type': 'string', 'children': [], 'value': '"Has calls"'},{'id': '310', 'type': 'else_clause', 'children': ['311']},{'id': '311', 'type': 'block', 'children': ['312']},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'binary_operator', 'children': ['317', '318'], 'value': '+'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'empty_box'},{'id': '318', 'type': 'string', 'children': [], 'value': '"No calls"'},{'id': '319', 'type': 'if_statement', 'children': ['320', '323', '331']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'has_network'},{'id': '323', 'type': 'block', 'children': ['324']},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'binary_operator', 'children': ['329', '330'], 'value': '+'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'filled_box'},{'id': '330', 'type': 'string', 'children': [], 'value': '"Has network"'},{'id': '331', 'type': 'else_clause', 'children': ['332']},{'id': '332', 'type': 'block', 'children': ['333']},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'binary_operator', 'children': ['338', '339'], 'value': '+'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'empty_box'},{'id': '339', 'type': 'string', 'children': [], 'value': '"No network"'}
def describe(self): def format_int(name, n): if n == 0 or n == 1: return "%i %s" % (n, name[:-1]) else: return "%i %s" % (n, name) empty_box = Colors.OKGREEN + '[ ]' + Colors.ENDC + ' ' filled_box = Colors.OKGREEN + '[x]' + Colors.ENDC + ' ' if self.start_time is None: print(empty_box + "No records stored") else: print((filled_box + format_int("records", len(self.records)) + " from %s to %s" % (self.start_time, self.end_time))) nb_contacts = bc.individual.number_of_contacts( self, interaction='callandtext', groupby=None) nb_contacts = nb_contacts['allweek']['allday']['callandtext'] if nb_contacts: print(filled_box + format_int("contacts", nb_contacts)) else: print(empty_box + "No contacts") if self.has_attributes: print(filled_box + format_int("attributes", len(self.attributes))) else: print(empty_box + "No attribute stored") if len(self.antennas) == 0: print(empty_box + "No antenna stored") else: print(filled_box + format_int("antennas", len(self.antennas))) if self.has_recharges: print(filled_box + format_int("recharges", len(self.recharges))) else: print(empty_box + "No recharges") if self.has_home: print(filled_box + "Has home") else: print(empty_box + "No home") if self.has_text: print(filled_box + "Has texts") else: print(empty_box + "No texts") if self.has_call: print(filled_box + "Has calls") else: print(empty_box + "No calls") if self.has_network: print(filled_box + "Has network") else: print(empty_box + "No network")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'matrix_index'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '5', 'type': 'block', 'children': ['6', '29']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'other_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': 'list_comprehension', 'children': ['13', '14', '23']},{'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', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'network'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'if_clause', 'children': ['24']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '!='},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'binary_operator', 'children': ['31', '35'], 'value': '+'},{'id': '31', 'type': 'list', 'children': ['32'], 'value': '[user.name]'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'other_keys'}
def matrix_index(user): other_keys = sorted([k for k in user.network.keys() if k != user.name]) return [user.name] + other_keys
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'clustering_coefficient_weighted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '19', '34', '44', '51', '55', '130', '146']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'matrix_undirected_weighted'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '22', 'type': 'list_comprehension', 'children': ['23', '24', '27', '30']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '30', 'type': 'if_clause', 'children': ['31']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'if_statement', 'children': ['35', '41']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '40'], 'value': '=='},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'max_weight'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'triplet_weight'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'for_statement', 'children': ['56', '59', '70']},{'id': '56', 'type': 'pattern_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'combinations'},{'id': '61', 'type': 'argument_list', 'children': ['62', '69']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '69', 'type': 'integer', 'children': [], 'value': '2'},{'id': '70', 'type': 'block', 'children': ['71', '93', '107']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '77']},{'id': '73', 'type': 'pattern_list', 'children': ['74', '75', '76']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'a_b'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'a_c'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'b_c'},{'id': '77', 'type': 'expression_list', 'children': ['78', '83', '88']},{'id': '78', 'type': 'subscript', 'children': ['79', '82']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '83', 'type': 'subscript', 'children': ['84', '87']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'subscript', 'children': ['89', '92']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'if_statement', 'children': ['94', '105']},{'id': '94', 'type': 'boolean_operator', 'children': ['95', '102'], 'value': 'or'},{'id': '95', 'type': 'boolean_operator', 'children': ['96', '99'], 'value': 'or'},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'is'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'a_b'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'a_c'},{'id': '101', 'type': 'None', 'children': []},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'is'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'b_c'},{'id': '104', 'type': 'None', 'children': []},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'continue_statement', 'children': []},{'id': '107', 'type': 'if_statement', 'children': ['108', '113']},{'id': '108', 'type': 'boolean_operator', 'children': ['109', '112'], 'value': 'and'},{'id': '109', 'type': 'boolean_operator', 'children': ['110', '111'], 'value': 'and'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'a_b'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'a_c'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'b_c'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'augmented_assignment', 'children': ['116', '117'], 'value': '+='},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'triplet_weight'},{'id': '117', 'type': 'binary_operator', 'children': ['118', '129'], 'value': '/'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '125'], 'value': '**'},{'id': '119', 'type': '()', 'children': ['120']},{'id': '120', 'type': 'binary_operator', 'children': ['121', '124'], 'value': '*'},{'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '*'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'a_b'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'a_c'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'b_c'},{'id': '125', 'type': '()', 'children': ['126']},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '/'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'integer', 'children': [], 'value': '3'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'max_weight'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'd_ego'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '135', 'type': 'generator_expression', 'children': ['136', '137', '142']},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'for_in_clause', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '141', 'type': 'integer', 'children': [], 'value': '0'},{'id': '142', 'type': 'if_clause', 'children': ['143']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': '>'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'conditional_expression', 'children': ['148', '159', '162'], 'value': 'if'},{'id': '148', 'type': 'binary_operator', 'children': ['149', '152'], 'value': '/'},{'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '*'},{'id': '150', 'type': 'integer', 'children': [], 'value': '2'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'triplet_weight'},{'id': '152', 'type': '()', 'children': ['153']},{'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '*'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'd_ego'},{'id': '155', 'type': '()', 'children': ['156']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '-'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'd_ego'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': '>'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'd_ego'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'integer', 'children': [], 'value': '0'}
def clustering_coefficient_weighted(user, interaction=None): matrix = matrix_undirected_weighted(user, interaction=interaction) weights = [weight for g in matrix for weight in g if weight is not None] if len(weights) == 0: return None max_weight = max(weights) triplet_weight = 0 for a, b in combinations(range(len(matrix)), 2): a_b, a_c, b_c = matrix[a][b], matrix[a][0], matrix[b][0] if a_b is None or a_c is None or b_c is None: continue if a_b and a_c and b_c: triplet_weight += (a_b * a_c * b_c) ** (1 / 3) / max_weight d_ego = sum(1 for i in matrix[0] if i > 0) return 2 * triplet_weight / (d_ego * (d_ego - 1)) if d_ego > 1 else 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'assortativity_indicators'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '5', 'type': 'block', 'children': ['6', '13', '20', '27', '37', '73', '165', '169', '185']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'matrix_undirected_unweighted'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'count_indicator'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'total_indicator'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ego_indics'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '36', 'type': 'True', 'children': []},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ego_indics'},{'id': '40', 'type': 'dictionary_comprehension', 'children': ['41', '44', '53']},{'id': '41', 'type': 'pair', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '44', 'type': 'for_in_clause', 'children': ['45', '48']},{'id': '45', 'type': 'pattern_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ego_indics'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'if_clause', 'children': ['54']},{'id': '54', 'type': 'boolean_operator', 'children': ['55', '66'], 'value': 'and'},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '59'], 'value': 'and'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '!='},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '58', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '65'], 'value': '!='},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '62', 'type': 'slice', 'children': ['63', '64']},{'id': '63', 'type': 'colon', 'children': []},{'id': '64', 'type': 'integer', 'children': [], 'value': '11'},{'id': '65', 'type': 'string', 'children': [], 'value': '"reporting__"'},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '72'], 'value': '!='},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '69', 'type': 'slice', 'children': ['70', '71']},{'id': '70', 'type': 'colon', 'children': []},{'id': '71', 'type': 'integer', 'children': [], 'value': '10'},{'id': '72', 'type': 'string', 'children': [], 'value': '"attributes"'},{'id': '73', 'type': 'for_statement', 'children': ['74', '77', '84']},{'id': '74', 'type': 'pattern_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'u_name'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'matrix_index'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '84', 'type': 'block', 'children': ['85', '97', '117', '127']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'correspondent'},{'id': '88', 'type': 'call', 'children': ['89', '94']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'network'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'u_name'},{'id': '96', 'type': 'None', 'children': []},{'id': '97', 'type': 'if_statement', 'children': ['98', '115']},{'id': '98', 'type': 'boolean_operator', 'children': ['99', '108'], 'value': 'or'},{'id': '99', 'type': 'boolean_operator', 'children': ['100', '103'], 'value': 'or'},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'correspondent'},{'id': '102', 'type': 'None', 'children': []},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '=='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'u_name'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '114'], 'value': '=='},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '114', 'type': 'integer', 'children': [], 'value': '0'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'continue_statement', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'neighbor_indics'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'correspondent'},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '126', 'type': 'True', 'children': []},{'id': '127', 'type': 'for_statement', 'children': ['128', '129', '130']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ego_indics'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'if_statement', 'children': ['132', '143']},{'id': '132', 'type': 'boolean_operator', 'children': ['133', '138'], 'value': 'and'},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '137'], 'value': 'is'},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'ego_indics'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '137', 'type': 'None', 'children': []},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '142'], 'value': 'is'},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'neighbor_indics'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '142', 'type': 'None', 'children': []},{'id': '143', 'type': 'block', 'children': ['144', '150']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'augmented_assignment', 'children': ['146', '149'], 'value': '+='},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'total_indicator'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'augmented_assignment', 'children': ['152', '155'], 'value': '+='},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'count_indicator'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '164'], 'value': '**'},{'id': '156', 'type': '()', 'children': ['157']},{'id': '157', 'type': 'binary_operator', 'children': ['158', '161'], 'value': '-'},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'ego_indics'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'neighbor_indics'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '164', 'type': 'integer', 'children': [], 'value': '2'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'assortativity'},{'id': '168', 'type': 'dictionary', 'children': []},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '172']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'count_indicator'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '178']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'assortativity'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '178', 'type': 'binary_operator', 'children': ['179', '182'], 'value': '/'},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'count_indicator'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'total_indicator'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '185', 'type': 'return_statement', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'assortativity'}
def assortativity_indicators(user): matrix = matrix_undirected_unweighted(user) count_indicator = defaultdict(int) total_indicator = defaultdict(int) ego_indics = all(user, flatten=True) ego_indics = {a: value for a, value in ego_indics.items() if a != "name" and a[:11] != "reporting__" and a[:10] != "attributes"} for i, u_name in enumerate(matrix_index(user)): correspondent = user.network.get(u_name, None) if correspondent is None or u_name == user.name or matrix[0][i] == 0: continue neighbor_indics = all(correspondent, flatten=True) for a in ego_indics: if ego_indics[a] is not None and neighbor_indics[a] is not None: total_indicator[a] += 1 count_indicator[a] += (ego_indics[a] - neighbor_indics[a]) ** 2 assortativity = {} for i in count_indicator: assortativity[i] = count_indicator[i] / total_indicator[i] return assortativity
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'assortativity_attributes'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '5', 'type': 'block', 'children': ['6', '13', '33', '37', '96', '100', '159']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'matrix_undirected_unweighted'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '16', 'type': 'list_comprehension', 'children': ['17', '18', '27']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'network'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'if_clause', 'children': ['28']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': '!='},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'neighbors_attrbs'},{'id': '36', 'type': 'dictionary', 'children': []},{'id': '37', 'type': 'for_statement', 'children': ['38', '41', '48']},{'id': '38', 'type': 'pattern_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'u_name'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'matrix_index'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '48', 'type': 'block', 'children': ['49', '61', '81']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'correspondent'},{'id': '52', 'type': 'call', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'network'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'u_name'},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'if_statement', 'children': ['62', '79']},{'id': '62', 'type': 'boolean_operator', 'children': ['63', '72'], 'value': 'or'},{'id': '63', 'type': 'boolean_operator', 'children': ['64', '67'], 'value': 'or'},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'is'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'correspondent'},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '=='},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'u_name'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '78'], 'value': '=='},{'id': '73', 'type': 'subscript', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '76', 'type': 'integer', 'children': [], 'value': '0'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'continue_statement', 'children': []},{'id': '81', 'type': 'if_statement', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'correspondent'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'has_attributes'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '93']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'neighbors_attrbs'},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'correspondent'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'correspondent'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'assortativity'},{'id': '99', 'type': 'dictionary', 'children': []},{'id': '100', 'type': 'for_statement', 'children': ['101', '102', '105']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '105', 'type': 'block', 'children': ['106', '132', '146']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '111', 'type': 'generator_expression', 'children': ['112', '113', '116']},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '116', 'type': 'if_clause', 'children': ['117']},{'id': '117', 'type': 'boolean_operator', 'children': ['118', '121'], 'value': 'and'},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'in'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'neighbors_attrbs'},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '127'], 'value': '=='},{'id': '122', 'type': 'subscript', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '127', 'type': 'subscript', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'neighbors_attrbs'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'den'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '137', 'type': 'generator_expression', 'children': ['138', '139', '142']},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'id': '139', 'type': 'for_in_clause', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'neighbors'},{'id': '142', 'type': 'if_clause', 'children': ['143']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'in'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'neighbors_attrbs'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '151']},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'assortativity'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '151', 'type': 'conditional_expression', 'children': ['152', '155', '158'], 'value': 'if'},{'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '/'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'den'},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': '!='},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'den'},{'id': '157', 'type': 'integer', 'children': [], 'value': '0'},{'id': '158', 'type': 'None', 'children': []},{'id': '159', 'type': 'return_statement', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'assortativity'}
def assortativity_attributes(user): matrix = matrix_undirected_unweighted(user) neighbors = [k for k in user.network.keys() if k != user.name] neighbors_attrbs = {} for i, u_name in enumerate(matrix_index(user)): correspondent = user.network.get(u_name, None) if correspondent is None or u_name == user.name or matrix[0][i] == 0: continue if correspondent.has_attributes: neighbors_attrbs[correspondent.name] = correspondent.attributes assortativity = {} for a in user.attributes: total = sum(1 for n in neighbors if n in neighbors_attrbs and user.attributes[a] == neighbors_attrbs[n][a]) den = sum(1 for n in neighbors if n in neighbors_attrbs) assortativity[a] = total / den if den != 0 else None return assortativity
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'network_sampling'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'snowball'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '205', '226']},{'id': '16', 'type': 'if_statement', 'children': ['17', '18', '129']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'snowball'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'if_statement', 'children': ['20', '23', '29']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'raise_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': '"Must specify a starting user from whom to initiate the snowball"'},{'id': '29', 'type': 'else_clause', 'children': ['30']},{'id': '30', 'type': 'block', 'children': ['31', '41']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'pattern_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'agenda'},{'id': '36', 'type': 'expression_list', 'children': ['37', '39']},{'id': '37', 'type': 'list', 'children': ['38'], 'value': '[user]'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '39', 'type': 'list', 'children': ['40'], 'value': '[user]'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '41', 'type': 'while_statement', 'children': ['42', '48']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '47'], 'value': '>'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'agenda'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'block', 'children': ['49', '57', '80']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'agenda'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'dealphebetized_network'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '62', 'type': 'argument_list', 'children': ['63', '70']},{'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': 'parent'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'network'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '69', 'type': 'argument_list', 'children': []},{'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': 'k'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'for_statement', 'children': ['81', '82', '83']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'neighbor'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'dealphebetized_network'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'if_statement', 'children': ['85', '103']},{'id': '85', 'type': 'boolean_operator', 'children': ['86', '97'], 'value': 'and'},{'id': '86', 'type': 'boolean_operator', 'children': ['87', '92'], 'value': 'and'},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '91'], 'value': 'not'},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'neighbor'},{'id': '90', 'type': 'integer', 'children': [], 'value': '1'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': 'is'},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'neighbor'},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'None', 'children': []},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '102'], 'value': '<'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '103', 'type': 'block', 'children': ['104', '113']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'neighbor'},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'id': '113', 'type': 'if_statement', 'children': ['114', '119']},{'id': '114', 'type': 'attribute', 'children': ['115', '118']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'neighbor'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'network'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'agenda'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'push'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'neighbor'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'else_clause', 'children': ['130']},{'id': '130', 'type': 'block', 'children': ['131', '161', '178', '186']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '134', 'type': 'list_comprehension', 'children': ['135', '136', '144']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '136', 'type': 'for_in_clause', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '144', 'type': 'if_clause', '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': 'os'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '158']},{'id': '153', 'type': 'attribute', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'shuffled_files'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '170', 'type': 'lambda', 'children': ['171', '173']},{'id': '171', 'type': 'lambda_parameters', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '177', 'type': 'argument_list', 'children': []},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'user_names'},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'shuffled_files'},{'id': '183', 'type': 'slice', 'children': ['184', '185']},{'id': '184', 'type': 'colon', 'children': []},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '189', 'type': 'list_comprehension', 'children': ['190', '202']},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'read_csv'},{'id': '194', 'type': 'argument_list', 'children': ['195', '201']},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '197', 'type': 'slice', 'children': ['198', '199']},{'id': '198', 'type': 'colon', 'children': []},{'id': '199', 'type': 'unary_operator', 'children': ['200'], 'value': '-'},{'id': '200', 'type': 'integer', 'children': [], 'value': '4'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '202', 'type': 'for_in_clause', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'user_names'},{'id': '205', 'type': 'if_statement', 'children': ['206', '212']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '211'], 'value': '<'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'raise_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'string', 'children': [], 'value': '"Specified more users than records that exist, only {} records available"'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'to_csv'},{'id': '231', 'type': 'argument_list', 'children': ['232', '244']},{'id': '232', 'type': 'list_comprehension', 'children': ['233', '241']},{'id': '233', 'type': 'call', 'children': ['234', '239']},{'id': '234', 'type': 'attribute', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'bc'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '241', 'type': 'for_in_clause', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'filename'}
def network_sampling(n, filename, directory=None, snowball=False, user=None): if snowball: if user is None: raise ValueError("Must specify a starting user from whom to initiate the snowball") else: users, agenda = [user], [user] while len(agenda) > 0: parent = agenda.pop() dealphebetized_network = sorted(parent.network.items(), key=lambda k: random.random()) for neighbor in dealphebetized_network: if neighbor[1] not in users and neighbor[1] is not None and len(users) < n: users.append(neighbor[1]) if neighbor[1].network: agenda.push(neighbor[1]) else: files = [x for x in os.listdir(directory) if os.path.isfile(os.path.join(directory, x))] shuffled_files = sorted(files, key=lambda k: random.random()) user_names = shuffled_files[:n] users = [bc.read_csv(u[:-4], directory) for u in user_names] if len(users) < n: raise ValueError("Specified more users than records that exist, only {} records available".format(len(users))) bc.to_csv([bc.utils.all(u) for u in users], filename)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_csv'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'digits'},{'id': '8', 'type': 'integer', 'children': [], 'value': '5'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '26', '37', '52', '73', '181']},{'id': '13', 'type': 'if_statement', 'children': ['14', '20']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '24', 'type': 'list', 'children': ['25'], 'value': '[objects]'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '29', 'type': 'list_comprehension', 'children': ['30', '34']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '34', 'type': 'for_in_clause', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'all_keys'},{'id': '40', 'type': 'list_comprehension', 'children': ['41', '42', '45']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '57', 'type': 'argument_list', 'children': ['58', '62']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'all_keys'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '64', 'type': 'lambda', 'children': ['65', '67']},{'id': '65', 'type': 'lambda_parameters', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'all_keys'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '73', 'type': 'with_statement', 'children': ['74', '84']},{'id': '74', 'type': 'with_clause', 'children': ['75']},{'id': '75', 'type': 'with_item', 'children': ['76']},{'id': '76', 'type': 'as_pattern', 'children': ['77', '82']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '81', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '82', 'type': 'as_pattern_target', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '84', 'type': 'block', 'children': ['85', '94', '101', '136']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'writerow'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '101', 'type': 'function_definition', 'children': ['102', '103', '105']},{'id': '102', 'type': 'function_name', 'children': [], 'value': 'make_repr'},{'id': '103', 'type': 'parameters', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'if_statement', 'children': ['107', '110', '113', '129']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'is'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '109', 'type': 'None', 'children': []},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'elif_clause', 'children': ['114', '119']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'return_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'digits'},{'id': '129', 'type': 'else_clause', 'children': ['130']},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'return_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '136', 'type': 'for_statement', 'children': ['137', '138', '139']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '139', 'type': 'block', 'children': ['140', '161']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '145', 'type': 'generator_expression', 'children': ['146', '152']},{'id': '146', 'type': 'tuple', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'make_repr'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '152', 'type': 'for_in_clause', 'children': ['153', '156']},{'id': '153', 'type': 'pattern_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '160', 'type': 'argument_list', 'children': []},{'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': 'w'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'writerow'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'list_comprehension', 'children': ['168', '178']},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'make_repr'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '177', 'type': 'None', 'children': []},{'id': '178', 'type': 'for_in_clause', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '181', 'type': 'if_statement', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'string', 'children': [], 'value': '"Successfully exported {} object(s) to {}"'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '192', 'type': 'argument_list', 'children': ['193', '197']},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'filename'}
def to_csv(objects, filename, digits=5, warnings=True): if not isinstance(objects, list): objects = [objects] data = [flatten(obj) for obj in objects] all_keys = [d for datum in data for d in datum.keys()] field_names = sorted(set(all_keys), key=lambda x: all_keys.index(x)) with open(filename, 'w') as f: w = csv.writer(f) w.writerow(field_names) def make_repr(item): if item is None: return None elif isinstance(item, float): return repr(round(item, digits)) else: return str(item) for row in data: row = dict((k, make_repr(v)) for k, v in row.items()) w.writerow([make_repr(row.get(k, None)) for k in field_names]) if warnings: print("Successfully exported {} object(s) to {}".format(len(objects), filename))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '33']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_csv'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'records_path'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'antennas_path'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'attributes_path'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'recharges_path'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'network'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'duration_format'},{'id': '20', 'type': 'string', 'children': [], 'value': "'seconds'"},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'describe'},{'id': '23', 'type': 'True', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '26', 'type': 'True', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'drop_duplicates'},{'id': '32', 'type': 'False', 'children': []},{'id': '33', 'type': 'block', 'children': ['34', '38', '96', '110', '143', '147', '173', '177', '203', '228', '256', '265', '272']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'antennas'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'antennas_path'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'try_statement', 'children': ['44', '92']},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'with_statement', 'children': ['46', '56']},{'id': '46', 'type': 'with_clause', 'children': ['47']},{'id': '47', 'type': 'with_item', 'children': ['48']},{'id': '48', 'type': 'as_pattern', 'children': ['49', '54']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'antennas_path'},{'id': '53', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '54', 'type': 'as_pattern_target', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'csv_file'},{'id': '56', 'type': 'block', 'children': ['57', '66']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'DictReader'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'csv_file'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'antennas'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '71', 'type': 'generator_expression', 'children': ['72', '89']},{'id': '72', 'type': 'tuple', 'children': ['73', '76']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '75', 'type': 'string', 'children': [], 'value': "'antenna_id'"},{'id': '76', 'type': 'tuple', 'children': ['77', '83']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '82', 'type': 'string', 'children': [], 'value': "'latitude'"},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '88', 'type': 'string', 'children': [], 'value': "'longitude'"},{'id': '89', 'type': 'for_in_clause', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '92', 'type': 'except_clause', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'pass_statement', 'children': []},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'user_records'},{'id': '99', 'type': 'call', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'records_path'},{'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '+'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '109', 'type': 'string', 'children': [], 'value': "'.csv'"},{'id': '110', 'type': 'with_statement', 'children': ['111', '121']},{'id': '111', 'type': 'with_clause', 'children': ['112']},{'id': '112', 'type': 'with_item', 'children': ['113']},{'id': '113', 'type': 'as_pattern', 'children': ['114', '119']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'user_records'},{'id': '118', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '119', 'type': 'as_pattern_target', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'csv_file'},{'id': '121', 'type': 'block', 'children': ['122', '131']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'DictReader'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'csv_file'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '134', 'type': 'list_comprehension', 'children': ['135', '140']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_parse_record'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'duration_format'},{'id': '140', 'type': 'for_in_clause', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '146', 'type': 'None', 'children': []},{'id': '147', 'type': 'if_statement', 'children': ['148', '151']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'is'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'attributes_path'},{'id': '150', 'type': 'None', 'children': []},{'id': '151', 'type': 'block', 'children': ['152', '166']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'user_attributes'},{'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': 'os'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'attributes_path'},{'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '+'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '165', 'type': 'string', 'children': [], 'value': "'.csv'"},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': '_load_attributes'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'user_attributes'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'recharges'},{'id': '176', 'type': 'None', 'children': []},{'id': '177', 'type': 'if_statement', 'children': ['178', '181']},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': 'is'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'recharges_path'},{'id': '180', 'type': 'None', 'children': []},{'id': '181', 'type': 'block', 'children': ['182', '196']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'user_recharges'},{'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': 'os'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'recharges_path'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '+'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '195', 'type': 'string', 'children': [], 'value': "'.csv'"},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'recharges'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': '_load_recharges'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'user_recharges'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '208']},{'id': '205', 'type': 'pattern_list', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'bad_records'},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '210', 'type': 'argument_list', 'children': ['211', '212', '213', '214', '215', '216', '217', '218', '219', '222', '225']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'antennas'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'recharges'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'antennas_path'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'attributes_path'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'recharges_path'},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'describe'},{'id': '221', 'type': 'False', 'children': []},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'drop_duplicates'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'drop_duplicates'},{'id': '228', 'type': 'if_statement', 'children': ['229', '232']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '231'], 'value': 'is'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'network'},{'id': '231', 'type': 'True', 'children': []},{'id': '232', 'type': 'block', 'children': ['233', '250']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'network'},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': '_read_network'},{'id': '240', 'type': 'argument_list', 'children': ['241', '242', '243', '244', '245', '246', '247']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'records_path'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'attributes_path'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'read_csv'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'antennas_path'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'drop_duplicates'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'drop_duplicates'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'recompute_missing_neighbors'},{'id': '255', 'type': 'argument_list', 'children': []},{'id': '256', 'type': 'if_statement', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'describe'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'describe'},{'id': '264', 'type': 'argument_list', 'children': []},{'id': '265', 'type': 'if_statement', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'return_statement', 'children': ['269']},{'id': '269', 'type': 'expression_list', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'bad_records'},{'id': '272', 'type': 'return_statement', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'user'}
def read_csv(user_id, records_path, antennas_path=None, attributes_path=None, recharges_path=None, network=False, duration_format='seconds', describe=True, warnings=True, errors=False, drop_duplicates=False): antennas = None if antennas_path is not None: try: with open(antennas_path, 'r') as csv_file: reader = csv.DictReader(csv_file) antennas = dict((d['antenna_id'], (float(d['latitude']), float(d['longitude']))) for d in reader) except IOError: pass user_records = os.path.join(records_path, user_id + '.csv') with open(user_records, 'r') as csv_file: reader = csv.DictReader(csv_file) records = [_parse_record(r, duration_format) for r in reader] attributes = None if attributes_path is not None: user_attributes = os.path.join(attributes_path, user_id + '.csv') attributes = _load_attributes(user_attributes) recharges = None if recharges_path is not None: user_recharges = os.path.join(recharges_path, user_id + '.csv') recharges = _load_recharges(user_recharges) user, bad_records = load(user_id, records, antennas, attributes, recharges, antennas_path, attributes_path, recharges_path, describe=False, warnings=warnings, drop_duplicates=drop_duplicates) if network is True: user.network = _read_network(user, records_path, attributes_path, read_csv, antennas_path, warnings, drop_duplicates=drop_duplicates) user.recompute_missing_neighbors() if describe: user.describe() if errors: return user, bad_records return user
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_conversations'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'keyword_argument', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'hours'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'block', 'children': ['16', '20', '24', '109']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'last_time'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '23', 'type': 'list', 'children': [], 'value': '[]'},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '27']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '27', 'type': 'block', 'children': ['28', '103']},{'id': '28', 'type': 'if_statement', 'children': ['29', '40', '72']},{'id': '29', 'type': 'boolean_operator', 'children': ['30', '33'], 'value': 'or'},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'last_time'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '39'], 'value': '<'},{'id': '34', 'type': 'binary_operator', 'children': ['35', '38'], 'value': '-'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'last_time'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'if_statement', 'children': ['42', '47', '55']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': '=='},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '46', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '55', 'type': 'else_clause', 'children': ['56']},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'if_statement', 'children': ['58', '64']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '63'], 'value': '!='},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'block', 'children': ['65', '68']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'yield', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '71', 'type': 'list', 'children': [], 'value': '[]'},{'id': '72', 'type': 'else_clause', 'children': ['73']},{'id': '73', 'type': 'block', 'children': ['74', '85']},{'id': '74', 'type': 'if_statement', 'children': ['75', '81']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '80'], 'value': '!='},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '80', 'type': 'integer', 'children': [], 'value': '0'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'yield', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '85', 'type': 'if_statement', 'children': ['86', '91', '96']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': '=='},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'interaction'},{'id': '90', 'type': 'string', 'children': [], 'value': "'call'"},{'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': 'results'},{'id': '95', 'type': 'list', 'children': [], 'value': '[]'},{'id': '96', 'type': 'else_clause', 'children': ['97']},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '101', 'type': 'list', 'children': ['102'], 'value': '[g]'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'last_time'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '109', 'type': 'if_statement', 'children': ['110', '116']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '115'], 'value': '!='},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '115', 'type': 'integer', 'children': [], 'value': '0'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'yield', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'results'}
def _conversations(group, delta=datetime.timedelta(hours=1)): last_time = None results = [] for g in group: if last_time is None or g.datetime - last_time < delta: if g.interaction == 'text': results.append(g) else: if len(results) != 0: yield results results = [] else: if len(results) != 0: yield results if g.interaction == 'call': results = [] else: results = [g] last_time = g.datetime if len(results) != 0: yield results